Creating/Inserting Bookmarks

M

MattyP

Hello,
I am in need of some help regarding Bookmarks in MS Word. Is it possible to
create a macro (or might one already exist ?), that would be able to convert
certain text strings to Bookmarks throughout a document (i.e., if all the
text strings that needed to be converted were all of the same style, i.e.,
Heading 1) ? I have a number of documents that I'd like to add Bookmarks to
(upwards of 50 in each - all for category headings), and I'm thinking it
would be much easier to run a macro in each document (and have this done
automatically), rather than having to add all the Bookmarks manually.

Any help/guidance would be most appreciated !
Thanks,
- Matt
 
D

Doug Robbins - Word MVP on news.microsoft.com

The following will insert a bookmark with the name of Bookmark# where # is a
number that starts with 1 and increments for each bookmark inserted into the
document.

Make sure that the last paragraph of your document is not formatted with the
Heading 1 style otherwise, it will go into an endless loop

Selection.HomeKey wdStory
Selection.Find.Style = ActiveDocument.Styles("Heading 1")
Dim frange As Range
Dim i As Long
i = 1
With Selection.Find
Do While .Execute(FindText:="", Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindStop, MatchCase:=False) = True
Set frange = Selection.Range
ActiveDocument.Bookmarks.Add "Bookmark" & i, frange
i = i + 1
Selection.Collapse wdCollapseEnd
Loop
End With

--
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, originally posted via msnews.microsoft.com
 
M

MattyP

Hi Doug -
This is EXACTLY what I was looking for ! Thanks for the speedy (and
detailed) reply --- I really appreciate it !

- Matt
 

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