Bookmark Range

J

Jules

I am trying to find the code to set the range for a bookmark to be the text
between 2 characters (maybe, $ and #) and then create a bookmark around this
text. I would only need to do this once in the document so do not need it to
loop or anything.

Would anyone know how I could set this up please?
 
D

Doug Robbins - Word MVP

Use:

Dim bmrange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="$^?^?#", Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
Set bmrange = Selection.Range
bmrange.Start = bmrange.Start + 1
bmrange.End = bmrange.Start + 2
ActiveDocument.Bookmarks.Add "mybookmark", bmrange
Selection.Collapse wdCollapseEnd
Selection.MoveRight wdCharacter, 1
Loop
End With


--
Hope this helps,

Doug Robbins - Word MVP

Please reply only to the newsgroups unless you wish to obtain my services on
a paid professional basis.
 
J

Jules

Thanks Doug. If you see this question again, please disregard it as I
couldn't find this one and reposted it and then found this one.
 

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