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