View Single Post
 
Old 06-20-2011, 10:09 AM
webharvest webharvest is offline Windows Vista Office 2007
Novice
 
Join Date: Jun 2011
Posts: 6
webharvest is on a distinguished road
Default Update bookmarks and variables in document

I have a user form that I use to put information into bookmarks and docvariables. When I insert the text from the userform into a bookmark I do the following to reestablish the bookmark.

Code:
pStr = Replace(.PropName.Value, Chr(10), Chr(10) + Chr(9))
Set oRng = ActiveDocument.Bookmarks("PropName").Range
oRng.Text = pStr
ActiveDocument.Bookmarks.Add "PropName", oRng
The above code works great but here is my problem. When someone creates a new document from my template the user form comes up and everything is entered but I give the user the rights to update the word document after the form populates everything. So what I am seeing happen is the person goes to change the Proposal Name (PropName bookmark in the document) and since there are no spaces before or after the bookmark text they end up deleting the bookmark when they type the new name in. I believe this is because when you select the whole text it automatically selects the bookmark tags so when you start typing the new text the book mark is deleted.

1) So the best solution would be if I can somehow protect a bookmark from being deleted when inside the document but unlock it when I run the vba code above.
2) An alternative solution would be to add several spaces at the end of the text inside the bookmark when the above vba code creates the bookmark. This would make it harder to select everything and delete the bookmark.

I would like to make it impossible but I will take what I can get.

Thank you ahead of time.
Reply With Quote