Bookmarks

  • Thread starter Thread starter Q
  • Start date Start date
Q

Q

hi,
i am automating a letter thru vba with bookmarks, but i
need a certain number to appear in the letter three
times. everytime i put the bookmark for that number in
the next place it removes it from the last place i put
it. is it possible that one bookmark can be used multiple
times in one document? thanks in advance

~q
 
Each bookmark must have a unique name. But if you're saving the number into
a string (via Input Box or other method), then three different bookmarks can
be places to insert that string.

Word help: Overview of adding bookmarks
Word VBA help: Bookmarks Collection Object

Ed
 
Either use three different bookmarks or use cross-references to the bookmark
for the second and third appearance. If you insertion is overwriting the
bookmark, however, the latter approach will not work. A better approach is
to store the number as a custom document property and use a DocProperty
field to insert it in the document.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
Hi Q,

One of the problems with updating bookmarks with vba is that they tend to
get deleted in the process. The following macro shows how to replace a
specified bookmark's text with a new text string.

Cheers
PS: If all three instances are supposed to have the same value, you only
need one bookmark. Indeed, you can only have one instance of a bookmark in a
document, which may be part of your problem. The other two copies of the
value can be maintained and updated via REF fields.

Sub UpdateBookMark()
Dim strNewText As String
Dim intBmkLength As Integer, rngTemp As Range
BmkNm = "Bookmark Name"
strNewText = "New Bookmark Text"
If ActiveDocument.Bookmarks.Exists(BmkNm) Then
Set rngTemp = ActiveDocument.Bookmarks(BmkNm).Range
rngTemp.Text = strNewText
ActiveDocuments.Bookmarks.Add BmkNm, rngTemp
Else
MsgBox "Bookmark " & BmkNm & " not found."
End If
Set rngTemp = Nothing
End Sub
 
Back
Top