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

VBA To Replace the Content of the Document Footer 1

Status
Not open for further replies.

autumnEND

Programmer
Nov 1, 2005
61
GB
Hi, i have a folder full of .wri document files , each document has a footer , what im wanting to do is loop through every document, change the footer to a value such as "new footer" and then output the document , with the changed footer.

I allready have code that opens each document, searches for a date within the document and changes it with a new date and then saves the new , but cant seem to get it to work with the footer.

Any ideas would be greatly appreciated.
Thanks in advance
 
Any chance you could explain us how you automate a .wri document ?
If by chance you do it with word when examine the code generated by the macrorecorder when doing the stuff manually.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I take it you are using Word to open the .wri files, do your stuff, then save them as Word docs? I am assuming this is the answer to PH's question.

In any case, footers can be tricky, although not difficult.

Are there going to be any Section breaks in the document? If not, then there is going to be only one footer...yes?

If this IS the case, you can access the footer directly. You can access all footers directly, but if there are section breaks, or different first page, different odd/even...then you have to deal with that.

By directly, I mean access the footer object without going into View > Header and Footer. Directly means there is no change in the UI.
Code:
ActiveDocument.Sections(1). _
    Footers(wdHeaderFooterPrimary).Range.Text = "Blah Blah Blah"
will replace the text of Footer(Primary) with "Blah Blah Blah".

Gerry
My paintings and sculpture
 
Hi, thanks for the replies .Yep i use Word to open the .wri files, make the changes, then save them as word docs . The documents always have the same footer throughout, it never changes, so will the above code change the footer content throughout the whole document?

Also if theres content e.g. "blah blah blah" and then a page number in the footer .
Would there be a way to replace the "blah blah blah" bit but leave the page numbers as they are.

Ill give it a try on monday when im back at work :)

Thanks .

 
I tried the code and it replaced the footer and inserted the new text.
How could i add text and page number on the same line, with text aligned central and page number aligned right.

so it looks something like this:

text goes here (page no)

when ever i change the text and then add a page number it displays it as 2 rows.

(pagenumber)
text goes here

any ideas would be appreciated
 
any chance you could post your actual code ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Yep sure, this is what i was trying to use to change the text and to add the page numbers.

With ActiveDocument.Sections(1)
.Footers(wdHeaderFooterPrimary).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Footers(wdHeaderFooterPrimary).Range.Font.Size = 10
.Footers(wdHeaderFooterPrimary).Range.Text = "Text content goes here"
.Footers(wdHeaderFooterPrimary).PageNumbers.Add _
PageNumberAlignment:=wdAlignPageNumberRight, _
FirstPage:=False
End With

maybe you will be able so see what im doing wrong :(
 
I managed to resolve my problem. By adding this into my code.

Dim rngFooter As Range

For Each rngFooter In ActiveDocument.StoryRanges
With rngFooter.Find
.Text = "Text To Change"
.Replacement.Text = "New Footer text"
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Next rngFooter

Thanks for any help given .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top