Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 05-12-2021, 03:05 PM
macropod's Avatar
macropod macropod is offline VBA/Macro for page numbering across multiple documents Windows 10 VBA/Macro for page numbering across multiple documents Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,465
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I seems to me that maintaining a 'main' document with INCLUDETEXT fields pointing to each of the 'secondary' documents would be no more onerous than using a macro employing an array of document names that is just as susceptible as INCLUDETEXT fields to your chapters being renamed.

As for your macro, the path is missing the final separator. The code could also be improved in other ways:
Code:
Sub PageNumberReset()
Application.ScreenUpdating = False
Dim pgNo As Long, n As Long
Dim StrPath As String
Dim ArrNames, wdDoc As Document

' Specify the path to the document files
StrPath = "C:\MyDocs\Example\"
' Create an array holding the document file names, in sequence
ArrNames = Array("Chap1.docx", "Chap2.docx", "Chap3.docx")

For n = 0 To UBound(ArrNames)
  Set wdDoc = Documents.Open(FileName:=StrPath & ArrNames(n), AddToRecentFiles:=False)
  With wdDoc
    With .Sections.First
      For Each HdFt In .Headers
        With HdFt
          If .Exists = True Then
            .PageNumbers.RestartNumberingAtSection = True
            .PageNumbers.StartingNumber = pgNo + 1
          End If
        End With
      Next
      For Each HdFt In .Footers
        With HdFt
          If .Exists = True Then
            .PageNumbers.RestartNumberingAtSection = True
            .PageNumbers.StartingNumber = pgNo + 1
          End If
        End With
      Next
    End With
    pgNo = pgNo + .ComputeStatistics(wdStatisticPages)
    .Close Savechanges:=wdSaveChanges
  End With
Next n

Set wdDoc = Nothing
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by Charles Kenyon; 05-13-2021 at 08:53 AM.
Reply With Quote
 

Tags
macro, pagenumber, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Page Numbering Macro mbr50 Word VBA 4 01-20-2020 04:47 PM
VBA/Macro for page numbering across multiple documents Multiple page numbering Spyke44 Word 4 10-18-2015 08:18 AM
VBA/Macro for page numbering across multiple documents Run a macro on multiple documents prakhil Word VBA 1 06-27-2014 06:20 AM
Multiple page document to individual multiple page documents Legger Mail Merge 3 06-15-2014 06:36 AM
VBA/Macro for page numbering across multiple documents page numbering across multiple documents reitdesign Word 3 12-12-2008 11:55 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:36 PM.


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