![]() |
|
#1
|
||||
|
||||
![]()
This would work but you might not like the global paragraph reset in the middle if you have paragraphs with local para formatting other than number resets.
Code:
Sub ToggleStyleNumbering2() Dim intResult As Integer, sFind As String, sReplace As String, iPage As Integer, aPar As Paragraph Dim aLT As ListTemplate 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 sFind = "Normal" sReplace = "List Number" ElseIf intResult = vbNo Then 'Remove Numbers sFind = "List Number" sReplace = "Normal" Else Exit Sub End If With ActiveDocument.Content.Find .ClearFormatting .Style = ActiveDocument.Styles(sFind) .Replacement.Style = ActiveDocument.Styles(sReplace) .Wrap = wdFindContinue .Execute Replace:=wdReplaceAll End With ActiveDocument.Range.ParagraphFormat.Reset 'clears all paragraph format resets If sReplace = "List Number" Then Set aLT = ActiveDocument.Styles("List Number").ListTemplate For Each aPar In ActiveDocument.Range.Paragraphs If aPar.Style = "List Number" Then If aPar.Range.Information(wdActiveEndPageNumber) > iPage Then aPar.Range.ListFormat.ApplyListTemplate ListTemplate:=aPar.Range.ListFormat.ListTemplate, ContinuePreviousList:=False, ApplyTo:=wdListApplyToWholeList iPage = aPar.Range.Information(wdActiveEndPageNumber) End If End If Next aPar End If End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#2
|
||||
|
||||
![]()
Hi Andrew
I'm seriously grateful for this! I've been tinkering around and digesting the code and understand the local-formatting issue. In fact, I discovered that the formatting issue is evident in the "old way" I was doing it, i.e. when manually restarting the numbering in a paragraph. Considering that any local paragraph formatting should be relatively limited anyway - as this is a script format with "layout rules" after all - your numbering system saves way more legwork than the minor issues it causes. One or two observations: Formatting wasn't always affected. Sometimes I would italicise a couple of lines and it stayed in place when toggling the numbering on and off, but if I italicised the whole paragraph (even ignoring the paragraph marker) then the formatting would reset. Individual words with local formatting (which is the much more likely scenario) never seem to be affected. So what's going on there? |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
kaurp | Word VBA | 5 | 11-02-2017 04:36 AM |
How can I define a numbering style restarting numbering after an outline by default | jklocker | Word | 1 | 09-26-2017 05:11 AM |
![]() |
jp91306 | Word | 3 | 01-01-2016 12:27 AM |
![]() |
cotjoey | Word | 11 | 09-21-2014 07:54 AM |
![]() |
Helix86 | Word | 5 | 08-07-2013 10:48 PM |