Add a bookmark that uses a string as the bookmark name?

J

James N.

i want to add bookmarks to a document that use the value of a string as the
bookmark name. An extract of the code is below.

strBookmarkID = DateID

mydoc.Bookmarks.Add Name:="strBookmarkID", Range:=Selection.Range

where DateID is the output of a function to create a unique string value for
the bookmark.

All i get is a bookmark named strBookmarkID and not the value of
strBookmarkID.

any ideas?

Thanks
 
L

Lene Fredborg

Remove the quotes around strBookmarkID:

mydoc.Bookmarks.Add Name:=strBookmarkID, Range:=Selection.Range


--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
S

Steve Yandl

In the line where you add the bookmark, get rid of the quotes around your
variable.
mydoc.Bookmarks.Add Name:="strBookmarkID", Range:=Selection.Range
should be
mydoc.Bookmarks.Add Name:=strBookmarkID, Range:=Selection.Range

Steve
 
J

James N.

Thanks Lene,

on looking at the DateID function i remembered that the format was T111-T222
and the - character is not allowed in bookmarks.

regards,

James
 
R

Russ

James,
An underscore character is legal for bookmark names.
Try:
mydoc.Bookmarks.Add Name:=Replace(strBookmarkID,"-","_"), _
Range:=Selection.Range

To give i.e., T111_T222
 

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