PDA

View Full Version : page numbering across multiple word docs



reitdesign
12-15-2008, 11:30 AM
hey everyone :hi:

i have a bunch of word documents that i had to separate because of file size. however, i need the page numbering on these to be constant throughout. is there a script that can be written that will automatically number the pages throughout the documents?

i would number the pages manually, but the page numbers of these documents are changing constantly, so it would be a real hassle to re-number everytime there's a change to one of the documents.

fumei
12-15-2008, 12:27 PM
Hmmmm. Tricky if you have multiple documents that any one of which can change the number of pages.

Doc_A = 10 pages
Doc_B = 20 pages (starting at 11...so 11 - 31)
Doc_C = 5 pages (starting at 32...so 32 - 37)
Doc_D = 10 pages (starting at 38...so 38 to 48)

Now suppose you make Doc_B = 23 pages. Doc_C has to be updated first before you get accurate numbering on Doc_D. In other words, when you opened Doc_D, to get accurate page numbering, you would have to open and check ALL the previous documents, because ANY of them could have changed.

Possible, but highly inefficient. What is the file size issue? Why do you care about on-going page numbers? I can see that if you print the documents (as a bunch) then sure, you want to get the page numbering correct. But for general use why is this important.

So, basically the answer is a qualified yes, you could write something that could do it...BUT, it would involve opening ALL the documents.

lucas
12-15-2008, 12:31 PM
Maybe combine them all into one file?

http://vbaexpress.com/kb/getarticle.php?kb_id=214

reitdesign
12-15-2008, 12:31 PM
thanks for responding!

the file sizes are anywhere from 1-15MB, depending on the number of images in it. i originally had them all in one document, but that filesize was ridiculous (150MB) so i split them into two documents, then ultimately 17 (by section).

the on-going page numbers are for printing them all at once. it should look like it came from one doc file.

fumei
12-15-2008, 02:03 PM
"it should look like it came from one doc file." This is not really meaningful. Here is another way you can print all the docs from a specified folder (in this case "c:\test\"), incrementing the page numbers as you go.

Sub blahblahblah()
Dim adoc
Dim j As Long
Dim path As String
' set the path string
path = "c:\test\"

' set up the Dir for all .doc files
adoc = Dir(path & "*.doc")

' DO until there are no more .doc files
Do While adoc <> ""
' open each file
Documents.Open FileName:=path & adoc
' increment the counter by the number of pages
j = j + ActiveDocument _
.Range.ComputeStatistics(wdStatisticPages)
' restart the number at the start of the doc
' with the counter number
' it is in the footer...
With Selection.Sections(1).Footers(1).PageNumbers
.RestartNumberingAtSection = True
.StartingNumber = j
End With
' print current doc
' and close without saving
With ActiveDocument
.PrintOut
.Close wdDoNotSaveChanges
End With
' go to the next file
adoc = Dir()
Loop
End Sub

reitdesign
12-22-2008, 08:58 AM
hey...thanks for the script!

unfortunately, when i plug it into word and try to run it, it doesn't work.
i copy/pasted it into Visual Basic Editor, and replaced the folder address ("c:\test\") to the folder that housed all my documents. but when i go to tools/macro/macros to run it, nothing happens. is there something i'm doing wrong?

fumei
12-22-2008, 12:10 PM
Have you tried running it from the VBE? What happens?

Have you tried stepping through it?