KRS
KRS

Reputation: 13

Need code to select entire text of just the current page footer

I am trying to select the entire contents of the current page footer before applying a specific style (Footer17) from the active document. Applying the Footer17 style without selecting all of the text applies the style to just the top line of the footer. The footer has three paragraph returns, but could be more than three lines depending on the document.

I've used the following code to remove LinkToPrevious on the footer in question:

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.HeaderFooter.LinkToPrevious = False

I've tried Selection.WholeStory, and also have tried to set a range that includes the text of just the current footer. But I can't consistently get the entire current footer selected.

Thanks in advance for any tips on how to do this.

Upvotes: 1

Views: 445

Answers (1)

Cindy Meister
Cindy Meister

Reputation: 25663

The following code will change the font of the Footer for the current selection. There is no need to actually put the focus in the footer, or select the content.

Selection.Sections(1).Footers(wdHeaderFooterPrimary).Range.Font.Name = "Footer17"

To perform multiple actions on the same Footer it makes sense to have an object:

Dim ftr as Word.HeaderFooter
Set ftr = Selection.Sections(1).Footers(wdHeaderFooterPrimary)
ftr.LinkToPrevious = False
ftr.Range.Font.Name = "Footer17"

Note that it's not possible to change the footer contents of only one page, unless that page is, by itself, a Section. Footers, by definition, extend across the entire document or, if "Link to previous" is not activated, across the entire section.

Note also that this code assumes there is only the one type of Footer (no "Different First Page" or "Even Page" options activated).

Upvotes: 1

Related Questions