View Single Post
 
Old 05-30-2021, 07:28 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,164
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote