Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-29-2021, 06: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
Question Restarting Paragraph/Style Numbering on Each New Page of a Document

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



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 09:58 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