Toggle filepath to footer

A

AngeloUCF

I'm trying to write a macro that I can link to a custom toolbar/button
that will add the file name and path of a document to the footer and
remove it if it has been added. It was pretty easy in excel but word
seems much more difficult for some reason. Here's one version that I
tried that doesn't work.

Function WordFilePath()
' WordFilePath Macro
Const wdFieldFileName = 29
If ActiveDocument.Sections(1).Footers(1).Show = True Then
Set objrange = ActiveDocument.Sections(1).Footers(1).Range
Set objField = objdoc.Fields.Add(objrange, wdFieldFileName)
Else
Set objrange = ActiveDocument.Sections(1).Footers(1).Range
Set objField = objdoc
End If

End Function
 
D

Doug Robbins - Word MVP

Use:

Dim afield As Field
Dim fexists As Boolean
fexists = False
For Each afield In ActiveDocument.Sections(1).Footers(1).Range.Fields
If afield.Type = wdFieldFileName Then
fexists = True
afield.Delete
End If
Next afield
If fexists = False Then
With ActiveDocument
.Fields.Add .Sections(1).Footers(1).Range, wdFieldEmpty, "filename
\p"
End With
End If


--
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, originally posted via msnews.microsoft.com
 
A

AngeloUCF

Thanks Doug, that seems to work just fine. Now my only problem is
figuring out how to get back the smiley after I deleted it from my
custom toolbar. It won't come back to the customize menu.
 

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