Disappearing bookmarks

E

Erik Lundberg

Hi anyone, I'm looking for a straightforward way if setting
values in bookmarks without them disappearing.
(Users of my work will then not be able to utilize the bookmarks that I've
populated)

This worked with DDE, but I want to use OLE.
This is how I do it.

ActiveDocument.Bookmarks("strBookMarkName").Range = strBookmarkValue

This causes the bookmark to disappear in faluor of the value but I want them
both.
 
M

Mark Tangard

Erik,

If you set up the bookmark to enclose a space: []
rather than to mark a spot: I
and use .Range.InsertAfter instead of .Range.Text
(using just .Range as in your code below isn't
strictly kosher), your code won't obliterate it.
 
M

mksmith

You're half way there. Before you overwrite the Range of the bookmark
save the range in a Range variable.

Then the next step is to change the value of the Range to the new text and
then add the bookmark to the Range.

It should work a little like this:


Sub UpdateBookmark (sBookmark as string, sValue as string)

Dim oRange as Range

If Documents.Count > 0 then
If ActiveDocument.Bookmarks.Exist (sBookmark) then
Set oRange = ActiveDocument.Bookmarks(sBookmark).Range
oRange.Text = sValue
ActiveDocuments.Bookmarks.Add sBookmark, oRange
End if
End if

End sub


Since I am just doing this from the top of my head it may need tweaking,
but you ought to get the idea.

Regards
Malc
www.dragondrop.com
 

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