Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Footer format in the whole document

Status
Not open for further replies.

ngardner

Technical User
Apr 1, 2002
35
0
0
AU
I am trying to write a macro that will change the format of all footers in the document (ie in every section of the document)
Our office has changed from a footer that contains the full file path, to just the file name. I would like to create a macro that staff can run if they bring up an old document and want to update all the footers in the document.
I can create a macro that does this, but how to I make it update each section?
Thanks
 
hi,

Something like this???
Code:
Sub atest()
    For Each s In ThisDocument.Sections
        With s
           For Each f In .Footers
            MsgBox f.Range.Text
           Next
        End With
    Next
End Sub


Skip,
[sub]
[glasses] [red]Be advised:[/red] Researchers have found another Descartes trueism, "Cogito ergo spud."
"I think; therefore, I YAM!
[tongue][/sub]
 
Hi,

If the existing footers are using FILENAME fields with the '\p' switch to insert the path, your macro could simply delete the '\p' switch or delete and reinsert the whole field (without the '\p' switch). The following macro takes the former approach:

Sub NewFooters()
Application.ScreenUpdating = False
ActiveWindow.View.ShowFieldCodes = True
For Each oSection In ActiveDocument.Sections
For Each oFoot In oSection.Footers
If Not oFoot.LinkToPrevious Then
With oFoot.Range.Find
.Text = "FILENAME \p"
.Replacement.Text = "FILENAME"
.Execute Replace:=wdReplaceAll
End With
oFoot.Range.Fields.Update
End If
Next
Next
ActiveWindow.View.ShowFieldCodes = False
Application.ScreenUpdating = True
End Sub

Cheers
PS: Unlike Skip's solution, the above code checks whether the section is linked to a previous one. This can save time if you have many linked sections in your document, since you'll only have to update the field once for each set of linked sections.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top