View Single Post
  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Suzanne S. Barnhill Suzanne S. Barnhill is offline
external usenet poster
 
Posts: 33,624
Default Macro to Generate Bookmarks Based on Text Style

You do know that the built-in heading styles are bookmarked automatically by
Word?

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org

"MattyP" wrote in message
...
Hello -
A few days ago, I posted a question to see if it were possible (and what
the
code might be) to create a macro that would autmatically add Bookmarks to
a
Word document, based on text style (in this case, Heading 1's). I got a
great reply (credit to the original responder !), but later realized it
would
definitely be helpful if I could tweak it a bit more.

The macro code originally provided is below. After running it, any text
strings formatted as Heading 1 are automatically identified as Bookmarks
(which is great). The catch is, these are named as "Bookmark 1",
"Bookmark
2", etc., rather than the being named the same as the actual text string
itself. So, the million dollar question is this --- is there any way to
modify the macro code below (or create a new one) that automatically
generates Bookmarks based on text style (i.e., Heading 1), and also names
them the same as the text string ? Any guidance would be most appreciated
!

- Matt

Here's the macro code I originally received (which works absolutely great,
but does name the Bookmarks "generically" --- 1,2,3, etc.)..........

------------------------------------------
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 3/8/2009 by MattyP
'
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

End Sub