Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 05-12-2021, 11:06 AM
Venteux Venteux is offline VBA/Macro for page numbering across multiple documents Windows 10 VBA/Macro for page numbering across multiple documents Office 2019
Novice
VBA/Macro for page numbering across multiple documents
 
Join Date: May 2021
Posts: 22
Venteux is on a distinguished road
Default VBA/Macro for page numbering across multiple documents

Hi all, I need to apply continuous page numbering across multiple documents. I have over 200 documents (chapters) with different authors that work on individual chapters. I can merge the documents at the end and have continuous page numbering but when I separate the documents again, the continuous page numbering is lost.



The {INCLUDETEXT} field isn't practical for me for several reasons: 1) if one or several of the chapters change, then I have to go back and manually update them again, 2) I do this task every year, so the title of the documents will change every year.

I found a macro (Automatic Page Numbers across Multiple Documents (Microsoft Word)) that seems like it would work, but it gives me an error and when I debug, this is the line that is problematic: "Application.Documents(thisFile).Close Savechanges:=wdSaveChanges"

Does anyone know what would cause this issue? I'm a VBA novice, so this is beyond me. I've specified my own path name and the file names for the array.

This is the whole code:

Code:
Sub PageNumberReset()
    Dim pgNo As Long
    Dim n As Long
    Dim pathName As String
    Dim fileNames
    Dim thisFile As String
    Dim aRange As Range

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

    pgNo = 0
    For n = 0 To UBound(fileNames)
        thisFile = pathName & fileNames(n)
        Application.Documents.Open (thisFile)
        ActiveDocument.Sections(1).Headers(1).PageNumbers.StartingNumber = pgNo + 1
        Set aRange = ActiveDocument.Range
        aRange.Collapse Direction:=wdCollapseEnd
        aRange.Select
        pgNo = Selection.Information(wdActiveEndAdjustedPageNumber)
        Application.Documents(thisFile).Close Savechanges:=wdSaveChanges
    Next n
End Sub

Can anyone help with this?

Last edited by macropod; 05-12-2021 at 02:52 PM. Reason: Added code tags
Reply With Quote
 

Tags
macro, pagenumber, vba



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:59 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