File location auto text

L

Linda RQ

Hi everyone,

Before I open up each document and do this one at a time I was wondering if
there is a way to add the auto text for file location to my documents all at
once?

I have about 100 documents in the same folder. The process I am planning is
to open the document/insert file location into the header or footer/print
each document. This is so 10 people have copies and the group can determine
which documents will be kept and which ones will go.

Thanks,
Linda
 
D

Doug Robbins - Word MVP

If you have all of the documents in a folder, running a macro containing the
following code will add the path and filename to the primary footer of the
first section of the document. Change the C:\test to whereever you have the
documents.

Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim myrange As Range

PathToUse = "C:\Test\"
'Set the directory and type of file to batch process
myFile = Dir$(PathToUse & "*.doc")
While myFile <> ""
'Open document
Set myDoc = Documents.Open(PathToUse & myFile)
Set myrange = myDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range
myrange.Collapse wdCollapseStart
myDoc.Fields.Add myrange, wdFieldEmpty, "Filename \p"
myrange.Fields.Update
'Close the modified document after saving changes
myDoc.Close SaveChanges:=wdSaveChanges
'Next file in folder
myFile = Dir$()
Wend

See the article "What do I do with macros sent to me by other newsgroup
readers to help me out?" at:

http://www.word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

Linda RQ

Thanks Doug. The documents are on a network drive. Does that require any
additional text? I printed this and the Macro Instructions so when I get to
work tomorrow, it will be sitting there ready for me to try it. The "What
to do with a Macro" article is a great thing to add to this...I have worked
with very few macros and needed to be pulled along each step.

Linda
 
D

Doug Robbins - Word MVP

Only the path to the folder where the files are located. (It would however
be a good idea to try it on a copy of the files in the first instance and
for that purpose, you might create a folder called Test on your C:Drive and
then copy the files there.)

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

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