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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace All in Footer

Status
Not open for further replies.

noHandlebars

Technical User
Jun 25, 2008
46
US
I'm trying to run a replace all in a footer and it's not working really at all. When i run it from the document it doesn't replace anything. I then tried running it after clicking inside the footer and the replace all only replaced the first occurence of the word. Any suggestions?
 




Hi,

"I'm trying to run a..."

"Any suggestions?"

How about more specific information, like what you are running.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I'm trying to create a macro that does a replace all.

So far all I can't even get the built in replace all function to work like I said above
 



"I'm trying to run a ..."

"I then tried running ..."

Please tell us exactly WHAT you are running: your CODE!

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I'm still trying to develop the code. All I've tried running is the built in replace all function in word. This is more of a question on why the replace function does not look/work in footers.
 





Check out the Sections collection, HeadersFooters collection to loop thru each one and do your find/replace.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
What do you mean by "Sections collection, HeadersFooters collection
 
When in VBE feel free to play with the F2 and F1 keys.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
OK.

noHandlebars, you are posting the question in the Office forum as well. Please tell us what you are attempting to do.

If you are trying to action via code (this is a VBA issue), then stick to this thread.

Replace does work in footers. If it is not doing this for you, then perhaps you need to do a Repair. Perhaps. But are you indeed using Replace All?

Just to help a bit....

All Word documents have Sections. They may have only one, but they have at least one. Sections are an very important part of the object model of Word.

Collections are just that. Collections of objects. So, the Section Collection is the collection of Section objects.

HeaderFooters are objects as well. They are child objects of Sections. The collection of them is the HeaderFooter collection.

Every Section has six headerfooter objects - three for the header, three for the footer. They can not be deleted, and exist whether you have put contents(text/graphics) into them, or not.
Code:
Dim r As Range
Dim oHF As HeaderFooter
Dim oSection As Section

For Each oSection In ActiveDocument.Sections
   For Each oHF In oSection.Footers
      Set r = oHF.Range
      With r.Find
         .Text = "yadda"
         .Replacement.Text = "Yogi Bear"
         .Execute Replace:=wdReplaceAll
      End With
   Next
Next
The above will replace all instances of "yadda" with "Yogi Bear" in all footers, in all Sections.

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top