PDA

View Full Version : Moving between footer and text



robinmk
06-23-2010, 04:29 AM
Hi,

I've use the macro recorder to create the following:

WordBasic.ViewFooterOnly
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[INSERT NAME OF CONTRACTOR]"
.Replacement.Text = "John Smith"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else

I'm assuming that WordBasic.ViewFooterOnly selects the footer, so what is the command to switch back to text (or deselect footer)?

Many Thanks

avtarxing
06-23-2010, 08:23 AM
use this to bring the focus out of your footer to the word document.

ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

fumei
06-23-2010, 09:00 AM
Better yet, do not use View at all. In code you never have to use Selection, and thus never have to leave the text layer. You do NOT have to go into the footer to action things into the footer. You do NOT have to change focus at all. If the purpose is to change the text

[INSERT NAME OF CONTRACTOR]

to

John Smith

thenSub ChangeFooter()
Selection.Sections(1).Footers(1).Range.Text = _
Replace(Selection.Sections(1).Footers(1).Range.Text, _
"[INSERT NAME OF CONTRACTOR]", _
"John Smith")
End Sub
changes the Primary footer of the section the cursor is in (the Selection), replacing the text.

Note:

1. if the text is NOT there you should test for errors.
2. if the footer is not Primary you should test for that
3. it would better to change the footer knowing which one is to be changed
4 it would be even better to change the text through a change in bookmark, or a field

robinmk
06-23-2010, 10:03 AM
Many Thanks

robinmk
06-25-2010, 03:13 AM
Ooops!

When I run the fumei's bit of code the 'page x of y' in the footer is no longer incremental. so just reads 'page 1 of 23' on all pages in that section. Any ideas?

fumei
06-25-2010, 08:03 AM
What version are you using (always helpful to mention)?

In any case, this is a known old bug.

Try: http://word.mvps.org/faqs/apperrors/pagexofy.htm