How to assign a value to a bookmark for the second time ?

O

Oscar

Is it possible to assign the value of a bookmark more than one time?

I've seen that Word deletes the bookmark when it is assigned a value by

objword.ActiveDocument.Bookmarks(NameOfBookmark).Select
objword.Selection.Text = NewValue

That's why I can't use this for the second time because the document doesn't
have the bookmarks anymore.

Oscar
 
J

Jonathan West

Oscar said:
Is it possible to assign the value of a bookmark more than one time?

I've seen that Word deletes the bookmark when it is assigned a value by

objword.ActiveDocument.Bookmarks(NameOfBookmark).Select
objword.Selection.Text = NewValue

That's why I can't use this for the second time because the document doesn't
have the bookmarks anymore.

Hi Oscar,

You need to recreate the bookmark. Take a look at this article

Inserting text at a bookmark without deleting the bookmark
http://www.mvps.org/word/FAQs/MacrosVBA/InsertingTextAtBookmark.htm
 
J

Jezebel

There's nothing to stop you re-adding the bookmark --

objword.ActiveDocument.Bookmarks(NameOfBookmark).Select
objword.Selection.Text = NewValue
objword.ActiveDocument.Bookmarks.Add Name:=NameOfBookMark,
Range:=objword.Selection
 
D

Doug Robbins - Word MVP - DELETE UPPERCASE CHARACT

Hi Oscar,

See the article “Inserting text at a bookmark without deleting the bookmark”
at:

http://www.mvps.org/word/FAQs/MacrosVBA/InsertingTextAtBookmark.htm

Instead of using bookmarks, you can use { DOCVARIABLE "varname" } fields and
then use

ActiveDocument.Variables("varname").Value = NewValue
ActiveDocument.Fields.Update

as many times as you wish.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
O

Oscar

thank you all for your help,

nice methods, especially that of variable adressing.

regards,
Oscar
 

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