Adding file information to a batch of documents

G

Guest

I have a group of documents, all saved in one folder, and I need to get the "file name" and "page x of y" added to the footer. I'm hoping this can be done in some kind of batch process. Any ideas?
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Christine,

The easiest way to do this is going to be to create and autotext entry that
contains the information in the way that you want it arranged.

Probably

Filename
Page X of Y

Do this using the autotext entries on the Headers and Footers toolbar. Now
select that information, and create a new autotext entry named "footer"
Before going any further, test this by typing footer and the press F3 to see
if it results in the information that you want.

When you have that right, the following code will insert that information
into the footer of a document

ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text =
"footer"
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.InsertAutoText

To do this for all of the documents in the one folder, use the following
code:

Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
PathToUse = "D:\Documents\" 'Replace with the correct path
myFile = Dir$(PathToUse & "*.doc")
While myFile <> ""
'Open document
Set myDoc = Documents.Open(PathToUse & myFile)
myDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text = "footer"
myDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range.InsertAutoText
'Save and Close
myDoc.Close SaveChanges:=wdSaveChanges
'Next file in folder
myFile = Dir$()
Wend

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top