C
Chuck
Hi all
I'd really appreciate some best practice advice re using VBA for setting up
list templates and styles for outline/paragraph numbering. We're getting
ready for a major format/style conversion and I'd like to make sure we get
paragraph numbering right.
We're staying with Word 2000 for the time being but working with documents
that were originally created in Word 2000 as well as WordPerfect (a variety
of versions) and Word 97.
We have a master "Normal" template with the new formatting and new styles.
I've developed a macro that uses .UpdateStyles (3 times) to try to update the
styles in the documents to be converted. Unfortunately .UpdateStyles (x3)
doesn't seem to update outline numbering on relevant styles reliably or
correctly. I've tried using .OrganizerCopy and that seems to do a better job
but even that doesn't seem to get the outline numbering right -- sometimes it
copies the outline linking correctly sometimes it doesn't and there doesn't
seem to be any particular pattern: it will get certain styles right in one
document but not in the next. (I don't know if that's a problem with lurking
legacy incompatibilities in the documents or what.)
I'm thinking that the only way to make sure that outline numbering and
linked styles in the styles in the converted documents are uniform and match
the styles in the new Normal template is to do it through VBA, by setting up
a macro (or series of macros) that define each and every style. Is that a
good idea or is there another way to do it?
BTW here's the code I've been using to try to get the styles copied over
just in case anyone can see something wrong in what I've been doing.
Thanks in advance for any advice! Chuck
Sub UpdateStyles()
Dim oLT As ListTemplate
Dim oStyle As Style
Dim sLKStyle As Variant
Dim i As Integer
Dim sStyleTemplate As String
On Error GoTo errorhandler
sStyleTemplate = "C:\Program Files\Microsoft
Office\Templates\NewNormal.dot"
With ActiveDocument
.AttachedTemplate = sStyleTemplate
.UpdateStyles
.UpdateStyles
.UpdateStyles
End With
For i = 1 To 5
Application.OrganizerCopy _
Source:=sStyleTemplate, _
Destination:=ActiveDocument.Path & "\" & ActiveDocument.Name, _
Name:="Level " & i, _
Object:=wdOrganizerObjectStyles
Next i
For i = 1 To 5
Application.OrganizerCopy _
Source:=sStyleTemplate, _
Destination:=ActiveDocument.Path & "\" & ActiveDocument.Name, _
Name:="NA - LEVEL " & i, _
Object:=wdOrganizerObjectStyles
Next i
'And so on, going through a number of different
'defined style/numbering hierarchies
'Relink levels to styles
Set oLT = ActiveDocument.Styles("Level 1").ListTemplate
For i = 1 To 5
sLKStyle = "Level " & i
oLT.ListLevels(i).LinkedStyle = sLKStyle
Next i
Set oLT = ActiveDocument.Styles("NA - LEVEL 1").ListTemplate
For i = 1 To 5
sLKStyle = "NA - LEVEL " & i
oLT.ListLevels(i).LinkedStyle = sLKStyle
Next i
'And so on, re-linking each number level to its LinkedStyle
MsgBox "Styles in this document have been updated.", _
vbOKOnly + vbInformation, "Styles Updated"
Exit Sub
errorhandler:
Select Case Err.Number
Case 91
MsgBox "Check " & sLKStyle & " to make sure " & _
"numbering and linked styles are correct.", _
vbExclamation + vbOKOnly, _
"Problem with numbering styles encountered"
Case Else
MsgBox Err.Number & " " & Err.Description
End Select
Resume Next
'Exit Sub
End Sub
I'd really appreciate some best practice advice re using VBA for setting up
list templates and styles for outline/paragraph numbering. We're getting
ready for a major format/style conversion and I'd like to make sure we get
paragraph numbering right.
We're staying with Word 2000 for the time being but working with documents
that were originally created in Word 2000 as well as WordPerfect (a variety
of versions) and Word 97.
We have a master "Normal" template with the new formatting and new styles.
I've developed a macro that uses .UpdateStyles (3 times) to try to update the
styles in the documents to be converted. Unfortunately .UpdateStyles (x3)
doesn't seem to update outline numbering on relevant styles reliably or
correctly. I've tried using .OrganizerCopy and that seems to do a better job
but even that doesn't seem to get the outline numbering right -- sometimes it
copies the outline linking correctly sometimes it doesn't and there doesn't
seem to be any particular pattern: it will get certain styles right in one
document but not in the next. (I don't know if that's a problem with lurking
legacy incompatibilities in the documents or what.)
I'm thinking that the only way to make sure that outline numbering and
linked styles in the styles in the converted documents are uniform and match
the styles in the new Normal template is to do it through VBA, by setting up
a macro (or series of macros) that define each and every style. Is that a
good idea or is there another way to do it?
BTW here's the code I've been using to try to get the styles copied over
just in case anyone can see something wrong in what I've been doing.
Thanks in advance for any advice! Chuck
Sub UpdateStyles()
Dim oLT As ListTemplate
Dim oStyle As Style
Dim sLKStyle As Variant
Dim i As Integer
Dim sStyleTemplate As String
On Error GoTo errorhandler
sStyleTemplate = "C:\Program Files\Microsoft
Office\Templates\NewNormal.dot"
With ActiveDocument
.AttachedTemplate = sStyleTemplate
.UpdateStyles
.UpdateStyles
.UpdateStyles
End With
For i = 1 To 5
Application.OrganizerCopy _
Source:=sStyleTemplate, _
Destination:=ActiveDocument.Path & "\" & ActiveDocument.Name, _
Name:="Level " & i, _
Object:=wdOrganizerObjectStyles
Next i
For i = 1 To 5
Application.OrganizerCopy _
Source:=sStyleTemplate, _
Destination:=ActiveDocument.Path & "\" & ActiveDocument.Name, _
Name:="NA - LEVEL " & i, _
Object:=wdOrganizerObjectStyles
Next i
'And so on, going through a number of different
'defined style/numbering hierarchies
'Relink levels to styles
Set oLT = ActiveDocument.Styles("Level 1").ListTemplate
For i = 1 To 5
sLKStyle = "Level " & i
oLT.ListLevels(i).LinkedStyle = sLKStyle
Next i
Set oLT = ActiveDocument.Styles("NA - LEVEL 1").ListTemplate
For i = 1 To 5
sLKStyle = "NA - LEVEL " & i
oLT.ListLevels(i).LinkedStyle = sLKStyle
Next i
'And so on, re-linking each number level to its LinkedStyle
MsgBox "Styles in this document have been updated.", _
vbOKOnly + vbInformation, "Styles Updated"
Exit Sub
errorhandler:
Select Case Err.Number
Case 91
MsgBox "Check " & sLKStyle & " to make sure " & _
"numbering and linked styles are correct.", _
vbExclamation + vbOKOnly, _
"Problem with numbering styles encountered"
Case Else
MsgBox Err.Number & " " & Err.Description
End Select
Resume Next
'Exit Sub
End Sub