View Single Post
 
Old 05-26-2011, 12:51 AM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Code:
Sub AddBookmark()
Dim oFld As Field, Rng As Range
For Each oFld In Selection.Fields
  If oFld.Type = wdFieldRef Then
    Set Rng = oFld.Result
    Rng.End = Rng.End + 1
    ActiveDocument.Bookmarks.Add Range:=Rng, Name:="test"
    Exit For
  End If
Next oFld
Set Rng = Nothing
End Sub
Note the 'Exit For'. This serves two purposes, it:
1. avoids needlessly checking any subsequent fields; and
2. prevents any attempt to re-use the bookmark - only one instance of a given bookmark can exist.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote