Results 1 to 2 of 2
  1. #1
    Star Lounger
    Join Date
    Dec 2005
    Posts
    53
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Macro to create bookmarks (Word 2003)

    I have a large glossary document with many entries that end in "See:" and a reference to another entry (for example: "See: kangaroo."). I'm looking for a macro that will take each instance of "See:" and turn the referenced entry title into a bookmark, and then insert a cross-reference to that bookmark. In the example above, the title of the "Kangaroo" entry becomes a bookmark, and "See: kangaroo" has a cross-reference to it.

    Of course, the word "kangaroo" might appear more than once in the glossary. But only the title of the "Kangaroo" entry will be in bold face, and that's how the macro will identify where to put the bookmark.

    Can this be done?

    Thanks,

    Dan

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro to create bookmarks (Word 2003)

    Depending on your document, the following may work or be very inefficient. It first bookmarks ALL bold words in the document, then loops through the occurrences of See: ...

    Sub SetBookmarksAndCrossReferences()
    Selection.HomeKey Unit:=wdStory
    With Selection.Find
    .Text = ""
    .Replacement.Text = ""
    .ClearFormatting
    .Replacement.ClearFormatting
    .Format = True
    .Font.Bold = True
    Do While .Execute = True
    ActiveDocument.Bookmarks.Add Name:=Selection.Text, _
    Range:=Selection.Range
    Loop
    End With
    Selection.HomeKey Unit:=wdStory
    With Selection.Find
    .Text = "See: "
    .Replacement.Text = ""
    .ClearFormatting
    .Replacement.ClearFormatting
    .Format = False
    Do While .Execute = True
    Selection.MoveRight Unit:=wdWord
    Selection.MoveRight Unit:=wdWord, Extend:=wdExtend
    If Right(Selection.Text, 1) = " " Then
    Selection.MoveEnd Unit:=wdCharacter, Count:=-1
    End If
    Selection.InsertCrossReference ReferenceType:=wdRefTypeBookmark, _
    ReferenceKind:=wdContentText, ReferenceItem:=Trim(Selection.Text), _
    InsertAsHyperlink:=True
    Loop
    End With
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •