Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-30-2021, 07:28 PM
Guessed's Avatar
Guessed Guessed is offline Restarting Paragraph/Style Numbering on Each New Page of a Document Windows 10 Restarting Paragraph/Style Numbering on Each New Page of a Document Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,176
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
  #2  
Old 05-31-2021, 04:35 AM
Matt C's Avatar
Matt C Matt C is offline Restarting Paragraph/Style Numbering on Each New Page of a Document Windows 10 Restarting Paragraph/Style Numbering on Each New Page of a Document Office 97-2003
Advanced Beginner
Restarting Paragraph/Style Numbering on Each New Page of a Document
 
Join Date: May 2021
Location: London, UK
Posts: 30
Matt C is on a distinguished road
Smile

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Restarting Paragraph/Style Numbering on Each New Page of a Document Restarting page numbering only if Section begins with Heading 1 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
Restarting Paragraph/Style Numbering on Each New Page of a Document RESTARTING page numbering in a sectioned document. jp91306 Word 3 01-01-2016 12:27 AM
Restarting Paragraph/Style Numbering on Each New Page of a Document Numbering not restarting at 1 between list styles cotjoey Word 11 09-21-2014 07:54 AM
Restarting Paragraph/Style Numbering on Each New Page of a Document reset numbering to 1 by paragraph Style Helix86 Word 5 08-07-2013 10:48 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:54 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft