A
Associates
Hi,
I was trying to add a new style into an existing word document (for office
word 2003). I want the following code to run when a user opens it so that it
would add this new marginstyle beforehand. So i call that function in the
AutoOpen macro. However, i got an error message.
Here is the code
Sub marginstyle()
Dim styleName As String
Dim oStyle As Style
styleName = "Section Document Heading 1"
'Create/Setup the style
For Each oStyle In ActiveDocument.Styles
If oStyle.NameLocal = styleName Then GoTo Setup
Next oStyle
ActiveDocument.Styles.Add Name:=styleName, Type:=wdStyleHeading1
Setup:
'With ActiveDocument.Styles(styleName)
' .AutomaticallyUpdate = False
' .BaseStyle = ""
' .NextParagraphStyle = "Normal"
'End With
With ActiveDocument.Styles(styleName).Font
.Size = 16
.ColorIndex = wdGreen
End With
MsgBox "Style setup completed"
End Sub
Sub AutoOpen()
Call marginstyle
End Sub
The error is at "ActiveDocument.Styles.Add Name:=styleName,
Type:=wdStyleHeading1". The description of it is "one of the values passed to
this method or property is out of range".
Any ideas?
Thank you in advance
I was trying to add a new style into an existing word document (for office
word 2003). I want the following code to run when a user opens it so that it
would add this new marginstyle beforehand. So i call that function in the
AutoOpen macro. However, i got an error message.
Here is the code
Sub marginstyle()
Dim styleName As String
Dim oStyle As Style
styleName = "Section Document Heading 1"
'Create/Setup the style
For Each oStyle In ActiveDocument.Styles
If oStyle.NameLocal = styleName Then GoTo Setup
Next oStyle
ActiveDocument.Styles.Add Name:=styleName, Type:=wdStyleHeading1
Setup:
'With ActiveDocument.Styles(styleName)
' .AutomaticallyUpdate = False
' .BaseStyle = ""
' .NextParagraphStyle = "Normal"
'End With
With ActiveDocument.Styles(styleName).Font
.Size = 16
.ColorIndex = wdGreen
End With
MsgBox "Style setup completed"
End Sub
Sub AutoOpen()
Call marginstyle
End Sub
The error is at "ActiveDocument.Styles.Add Name:=styleName,
Type:=wdStyleHeading1". The description of it is "one of the values passed to
this method or property is out of range".
Any ideas?
Thank you in advance