Listing Bookmarks ONLY in the header

R

rg

I have Bookmarks in the Header, Footer, and main, of the document.

How do I loop through and goto the bookmarks in the header only?
 
D

Doug Robbins - Word MVP

Dim hrange As Range
Dim abm As Bookmark
Set hrange = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
For Each abm In ActiveDocument.Bookmarks
If abm.Range.InRange(hrange) Then
MsgBox abm.Name & " is in the primary header of Section 1."
Else
MsgBox "Not in header"
End If
Next abm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
R

rg

Thank you - this is perfect as I can locate bookmarks in either the footer
or header by changing the .Header to .Footer.

What would the equivalent code be if I need to locate bookmarks solely in
the body of the document and exclude the Header and Footer.

I appreciate what you sent so far!!!
 
D

Doug Robbins - Word MVP

Dim hrange As Range
Dim abm As Bookmark
Set hrange = ActiveDocument.Range
For Each abm In ActiveDocument.Bookmarks
If abm.Range.InRange(hrange) Then
MsgBox abm.Name & " is in the body of the document."
Else
MsgBox abm.Name & " is not in the body of the document"
End If
Next abm

However, you should consider the information provided in the article "Using
a macro to replace text where ever it appears in a document including
Headers, Footers, Textboxes, etc." at:

http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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