Update Text In All Footers

D

Dave

Hi Everyone,

I have a VB macro that I need to add something to. I am trying to amend the
text in all footers.

I need the text to show:

"Document Title v1.0 " & "_" & PNAME & "_" & PCODE & ".doc"

where PNAME and PCODE have already been defined earlier.

Can anyone help?

Thanks! :)
Dave
 
H

Helmut Weber

Hi Dave,

abbreviated and simplified:

Sub SetFooter()
Dim rngStory As Range
For Each rngStory In ActiveDocument.StoryRanges
Select Case rngStory.StoryType
Case 11: rngStory.Text = "thistext first page footer"
Case 8: rngStory.Text = "thistext even page footer"
Case 9: rngStory.Text = "thistext primary footer"
End Select
Next
End Sub

For a full coverage, see:
http://word.mvps.org/FAQs/Customization/ReplaceAnywhere.htm


--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
F

fumei via OfficeKB.com

Hi Helmut,

Would it not be better to use a HeaderFooter object and explicitly (and only)
go through the Footer collection? I am trying to understand why it would be
good to go through all the StoryRanges. A For Each In StoryRanges also tests
Comments storyrange, Endnotes storyrange, MainText storyrange, Footnotes
storyrange...

Sub SpecificFooterText(PNAME As String, _
PCODE As String)
Dim oHF As HeaderFooter
Dim oSection As Section
For Each oSection In ActiveDocument.Sections
For Each oHF In oSection.Footers
oHF.Range.Text = _
"Document Title v1.0 " & "_" & _
PName & "_" & PCODE & ".doc"
Next
Next
End Sub

Would simply put the text in ALL footers.

Of course if different footers are required for DifferentFirstPage and
OddEven, that would have to be covered, but that is not difficult.

I am trying to understand why it would be good to use - in this case -
StoryRanges.

Gerry
 
H

Helmut Weber

Hi Gerry,
Would it not be better to use a HeaderFooter object
and explicitly (and only)
go through the Footer collection?

Yes, sure, in theory.

But how many milliseconds are gained, if any?

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

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