Finding Bookmarks in Headers

E

Edd

I need to be able to goto a bookmark in a header and I use several different
headers in the same document by using section breaks. I have not determined
how to do this since the headers are not visible in the goto list. I am
using word 2002 sp3
 
J

Jean-Guy Marcil

Edd was telling us:
Edd nous racontait que :
I need to be able to goto a bookmark in a header and I use several
different headers in the same document by using section breaks. I
have not determined how to do this since the headers are not visible
in the goto list. I am using word 2002 sp3

You have to familiarize yourself with storyranges.
You will find some example and maybe some light here:

http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm

;-)

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
E

Edd

Story Ranges were very cumbersom to work with so I did some experimentation
on that track and found this to work very well.

ActiveDocument.Bookmarks.Item("headerid2").Select

Where "headerid" was the bookmark for the header I was looking for. This
would find bookmarks in any header in the document.
 
J

Jean-Guy Marcil

Edd was telling us:
Edd nous racontait que :
Story Ranges were very cumbersom to work with so I did some
experimentation on that track and found this to work very well.

ActiveDocument.Bookmarks.Item("headerid2").Select

Where "headerid" was the bookmark for the header I was looking for.
This would find bookmarks in any header in the document.

Great! Never thought of using the Item method for grabbing a bookmark in a
header.

May I suggest that you avoid using the Selection object... you'll get in all
kinds of trouble. E.g., with your code, you end up in normal view with the
cursor in the header pane... you are going to have to add code to restore
the view to what it was or the user will be greatly annoyed (I know I
would!), or you may end up losing the bookmark itself if you manipulate the
text, etc.

The Range object is much more powerful and flexible.

Try something like this:
'_______________________________________
Dim MyRange As Range
Dim BookName As String

Set MyRange = ActiveDocument.Bookmarks.Item("TestHeader").Range

With MyRange
'Save the bookmark name
BookName = .Bookmarks(1).Name
.Text = "New super text."
'Resotre the bookmark or the text edition will delete it.
'Use the name saved above and the same range
.Bookmarks.Add BookName, MyRange
End With
'_______________________________________

HTH
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
E

Edd

Thanks for the input. will take this also and add it to my understanding.
Actually did handle this by reseting the view to normal since I had some
other operations to do. This is a macro intended to fill in a form.
 

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