>Hello all
>
[quoted text clipped - 7 lines]
>Thanks in advance,
>MMH.
Here are two ways to go about it:
(1) Iterate through the entire Styles collection, checking to see
whether any of them have the name you want to use...
Dim oStyle As Style, NewStyle As Style
Dim bFound As Boolean
Dim strNewStyle As String
strNewStyle = "FaxHeader"
For Each oStyle In ActiveDocument.Styles
If LCase(oStyle.NameLocal) = LCase(strNewStyle) Then
bFound = True
Exit For
End If
Next oStyle
If Not bFound Then
Set NewStyle = ActiveDocument.Styles.Add( _
Name:=strNewStyle, _
Type:=wdStyleTypeParagraph)
NewStyle.BaseStyle = ActiveDocument.Styles("Normal")
End If
(2) Use error-trapping. Try to use the style; if it doesn't exist, the
Err.Number property is assigned a nonzero value...
On Error Resume Next
If LCase(strNewStyle) <> "normal" Then
rgAT.Style = ActiveDocument.Styles(strNewStyle)
If Err.Number <> 0 Then
Err.Clear
' define & apply style
Set NewStyle = ActiveDocument.Styles.Add( _
Name:=strNewStyle, _
Type:=wdStyleTypeParagraph)
NewStyle.BaseStyle = ActiveDocument.Styles("Normal")
On Error Resume Next
rgAT.Style = ActiveDocument.Styles(strNewStyle)
End If
End If
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
MMH - 23 Jun 2005 05:06 GMT
Thank you - I used option 1 and it worked brilliantly.
MMH
> Here are two ways to go about it:
>
[quoted text clipped - 8 lines]
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org