Bookmarks - howto replace text

J

Jesper

Hi,

I have a word document that serves as a template. In this document a number of 'variable names' are to be replaced with their value. We've done this so far by writing the variables in the template on the form <!Price>, then we search the template for all <!, extract the variable name and retrieve its value in a another file, then make a substitution. It works fine, However when <!Price> is substituted with $22.50, we cant rerun the and substitue the price with a new price. Then we decided to use bookmarks. How is this done. We have managed to get access to all the bookmarks in the document. It seems that there are to types of bookmarks, some can hold text. How do you replace the shown text of a bookmark without deleting the bookmark. Is this the correct tecnique, do you know of any good samples of this problem.

thanks
Jesper.



I'm experiencing some problems using bookmarks.
 
J

Jezebel

Document properties are a better way to handle this. Set up the properties
using the File > Properties : Custom tab. Insert DocProperty fields in the
document where you want the values to appear. (Eg, you have a property
called Price, and use { DocProperty Price } to display it.)

The advantage is that you can reset the value as often as you like, without
have to do anything else in the document.




Jesper said:
Hi,

I have a word document that serves as a template. In this document a
number of 'variable names' are to be replaced with their value. We've done
this so far by writing the variables in the template on the form <!Price>,
then we search the template for all <!, extract the variable name and
retrieve its value in a another file, then make a substitution. It works
fine, However when <!Price> is substituted with $22.50, we cant rerun the
and substitue the price with a new price. Then we decided to use bookmarks.
How is this done. We have managed to get access to all the bookmarks in the
document. It seems that there are to types of bookmarks, some can hold text.
How do you replace the shown text of a bookmark without deleting the
bookmark. Is this the correct tecnique, do you know of any good samples of
this problem.
 
H

Helmut Weber

Hi Jesper,
just a demo, if has to be the range-object:
Dim oDcm As Document
Dim oRng As Range
' -----------
Sub Makro1()
Set oDcm = ActiveDocument
' there is a bookmark named "MyMark"
' remeber the range of the bookmark
Set oRng = oDcm.Bookmarks("MyMark").Range
' set the text
oRng.Text = "This Name"
' Bookmark has gone!, so define it anew
' the range is the remembered range
oDcm.Bookmarks.Add Name:="MyMark", Range:=oRng
End Sub
HTH
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 

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