macro to display document filepath

S

Satara15

I have a request from a user to provide a macro for Word XP that will display
the complete network filepath and document name as a footer in a document.
(i.e. S:\ALS\folder1\subfolder2\documentname).
I have no programming experience. Can anyone help me? Any response is
appreciated.

David
 
J

Jean-Guy Marcil

Satara15 was telling us:
Satara15 nous racontait que :
I have a request from a user to provide a macro for Word XP that will
display the complete network filepath and document name as a footer
in a document. (i.e. S:\ALS\folder1\subfolder2\documentname).
I have no programming experience. Can anyone help me? Any response is
appreciated.

You do not need a macro for that.

View > Header and Footer
Place the cursor in the footer
On the H/F toolbar, the first button is "Insert Autotext"
Choose "File Name and Location"

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

Jay Freedman

Satara15 said:
I have a request from a user to provide a macro for Word XP that will
display the complete network filepath and document name as a footer
in a document. (i.e. S:\ALS\folder1\subfolder2\documentname).
I have no programming experience. Can anyone help me? Any response is
appreciated.

David

Hi David,

You don't need a macro for this. Open the Footer pane, click the AutoText
button on the Header/Footer toolbar, and select "Filename and path". That
will insert a field to show the information.

You can also insert the same field without using AutoText. Click Insert >
Field > Filename and check the box for "Add path to filename", which gives a
field with the code {FILENAME \p}.

The field does not update automatically when you use File > Save As to make
a copy of the document with a different name. You can select the field and
press F9 to update it, or you can go to Print Preview (assuming "Update
fields" is checked in Tools > Options > Print).
 
S

Satara15

Merci, Jean-Guy!
Thank you, Jay.

Both replies were very helpful. It just goes to show you can teach an old
dog (me) new tricks.

David
 
C

Chuck

There may be times when you do need a macro to insert the path/filename (for
instance adding it to a menu/toolbar to make it easier for users to do
themselves, or to use as a component in another macro). Here's the code,
which you can also generate yourself using the Record Macro feature and then
creating the field while recording the macro. The code below will insert the
field wherever the cursor is -- you can create separate code that will insert
fields into headers/footers/etc.

Sub FilenameField()

Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:="FILENAME \p "

End Sub
 

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