Bookmarks

G

Guest

I've a template containing bookmarks and I've created a UserForm to populate
the bookmarked areas of the template. I've also cross-referenced the
bookmarks. Unfortunately, the information is replacing the bookmarks so the
cross-references don't work. How do I stop the bookmarks from being deleted?

Thanks for any help and assistance you can give me.
 
M

macropod

Hi Noella,

If your text goes into a formfield on the document, try something based on:

Sub UpdateBookmark (BmkNm as string, MyTxt as string)
If ActiveDocument.Bookmarks.Exists(BmkNm) Then
ActiveDocument.Bookmarks(BmkNm).Range.Fields(1).Result.Text = MyTxt
End if
End sub
where BmkNm and MyTxt are variables holding your bookmark name and text, respectively.

Otherwise, if you're just populating stanadard bookmarks, try:

Sub UpdateBookmark (BmkNm as string, MyTxt as string)
Dim BmkRng as Range
If ActiveDocument.Bookmarks.Exists(BmkNm) Then
Set BmkRng = ActiveDocument.Bookmarks(BmkNm).Range
BmkRng.Text = MyTxt
ActiveDocument.Bookmarks.Add BmkNm, BmkRng
End if
Set BmkRng = Nothing
End sub
where BmkNm and MyTxt are variables holding your bookmark name and text, respectively.

Cheers
 

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