Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bookmark Text 1

Status
Not open for further replies.

tyang01

Technical User
Feb 1, 2007
46
0
0
US
Hi I was wondering if there is a method of changing the bookmark text so I can reference them in multiple locations of word doc. I have created bookmarks and I am inserting information from a Access form. But instead of inserting it into the bookmark it inserts the information to the right of the bookmark. I know I can select the text and do a ctrl+i > k to make the text the bookmark text. but I want to change the text of bookmark. So I was wondering if there is a different mthod.

Thanks
 
Hi tyang01,

I take it that you're inserting the text with vba. What you need to do is to re-apply the bookmark to the inserted text. For example, you could call the following the macro with parameters for the bookmark’s name and new string:
Code:
Sub UpdateBookmark (BmkNm as string, NewTxt as string)
Dim BmkRng as Range
If Documents.Count > 0 then
	If ActiveDocument.Bookmarks.Exists(BmkNm) Then
		Set BmkRng = ActiveDocument.Bookmarks(BmkNm).Range
		BmkRng.Text = NewTxt
		ActiveDocument.Bookmarks.Add BmkNm, BmkRng
	End if
End if
Set BmkRng = Nothing
End sub
Cheers



[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top