Hi, VBA Pros
I'm currently using the code below to add or remove numbering to/from a specific custom style in a document.
All works perfectly but the numbering needs to
restart from "1" on each new page.
At the moment I'm simply scrolling through each page pressing Word's built-in "Restart Numbering" but I'm wondering if VBA can do it for me in one swift stroke. It can be an entirely separate macro if needs be.
The most important bit is that I must be able to toggle the numbers on and off without any undue complications, which the existing code allows.
EDIT: Just to add that "Custom Style Numbered" will not always be at the top of a page, if it makes any difference. The document contains a number of styles but this is the only one which should include optional numbering.
(This is something I've been battling with for several years, by the way!)
Quote:
Sub ToggleStyleNumbering()
'
Dim intResult As Integer
intResult = MsgBox("Would you like to add numbering to Custom Style?" & vbCrLf & vbCrLf & _
"Click 'Yes' to ADD or 'No' to REMOVE", vbYesNoCancel + vbQuestion, "Add or Remove Numbering")
If intResult = vbYes Then
'Add Numbers
With ActiveDocument.Content.Find
.ClearFormatting
.Style = ActiveDocument.Styles("Custom Style")
.Replacement.Style = ActiveDocument.Styles("Custom Style Numbered")
.Wrap = wdFindContinue
.Execute , , , , , , , , , , wdReplaceAll
End With
ElseIf intResult = vbNo Then
'Remove Numbers
With ActiveDocument.Content.Find
.ClearFormatting
.Style = ActiveDocument.Styles("Custom Style Numbered")
.Replacement.Style = ActiveDocument.Styles("Custom Style")
.Wrap = wdFindContinue
.Execute , , , , , , , , , , wdReplaceAll
End With
Else
Exit Sub
End If
End Sub
|
Thanks again in advance.