Finding Text in Footer

S

Sonny Maou

How do I determine (with VBA, of course) if some text, such as "Private
and Confidential," appears in the footer?

Thanks!
 
D

dz

From Word 2000+, the headers/footers situation changed
drastically. Here's the code to open any type of footer,
whether the section uses Different First Page or not:

(I realize the spacing looks goofy here, but it is set up
to directly paste into the VBA window:

Sub OpenFooters()

'Opens the current page footer pane
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or _
ActiveWindow.ActivePane.View.Type = wdOutlineView Or _
ActiveWindow.ActivePane.View.Type = wdMasterView Then
ActiveWindow.ActivePane.View.Type = wdPageView
End If
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter

End Sub

Once in the footer, then just perform a regular find or
replace operation for the text. Make sure that you set
the wrap portion of the "With Selection.Find" code of the
search with the following:

.Wrap = wdFindStop

To get back out of the footer (or a header) to the main
document, use the following code:

Sub OpenMain()
'
'Code places cursor in the document's main text on the
CURRENT page

If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or
ActiveWindow. _
ActivePane.View.Type = wdOutlineView Or
ActiveWindow.ActivePane.View.Type _
= wdMasterView Then
ActiveWindow.ActivePane.View.Type = wdPageView
End If

ActiveWindow.ActivePane.View.SeekView =
wdSeekMainDocument

End Sub

Hope this helps!

dz
 
D

dz

Ignore if the other reply went through - didn't seem to
show up.

****

From Word 2000+, the headers/footers situation changed
drastically. Here's the code to open any type of footer,
whether the section uses Different First Page or not:

(I realize the spacing looks goofy here, but it is set up
to directly paste into the VBA window:

Sub OpenFooters()

'Opens the current page footer pane
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or _
ActiveWindow.ActivePane.View.Type = wdOutlineView Or _
ActiveWindow.ActivePane.View.Type = wdMasterView Then
ActiveWindow.ActivePane.View.Type = wdPageView
End If
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageFooter

End Sub

Once in the footer, then just perform a regular find or
replace operation for the text. Make sure that you set
the wrap portion of the "With Selection.Find" code of the
search with the following:

.Wrap = wdFindStop

To get back out of the footer (or a header) to the main
document, use the following code:

Sub OpenMain()
'
'Code places cursor in the document's main text on the
CURRENT page

If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or
ActiveWindow. _
ActivePane.View.Type = wdOutlineView Or
ActiveWindow.ActivePane.View.Type _
= wdMasterView Then
ActiveWindow.ActivePane.View.Type = wdPageView
End If

ActiveWindow.ActivePane.View.SeekView =
wdSeekMainDocument


End Sub

Hope this helps.

dz
 
S

Sonny Maou

Thanks, dz...

Why does the macro recorder include all that other stuff? Why isn't

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter

by itself good enough?

Just curious. :)
 
D

dz

Boy, that is the question, isn't it?! I wish I had an
answer for you. I've spent many hours tweaking code that
was keyboard recorded but didn't work when re-run as a
macro. You just have to keep plugging away (or punt and
ask someone who suffered many hours on the same problem).

Hope it all works out for ya.

dz
 

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