issues with bookmarks

M

M.P. Frosch

I am working on a VBa application that will have a long series of pages
which ask questions and accumulate information that is then used to generate
a text document. While I am working on the VBA portion, I want to try
things out in order to make sure that formating and the like is correct. I
have placed a series of named bookmarks into my template in the correct
places -- but after I run the VBA application the first time the bookmarks
are all replaced with the inserted text. Short of closing the document and
re-openning the template how do I get around this for troubleshooting.

As a related question, I know that the VBA application will only run if a
document is opened from a template but would like to find a work-around for
the situation in which the user gets halfway through responding to the
application and answering the questions. Is there a way to save the
document back as a partially completed template to be re-opened when the
user returns? If so, how do I track which bookmarks have been replaced and
therefore which userforms should be hidden?

Thanks.

Matthew
 
D

Doug Robbins - Word MVP

Hi Mathew,

I would suggest that you use document variables and { DOCVARIABLE } fields
in your document rather than bookmarks. With a { DOCVARIABLE } field, you
can control the formatting by the addition of a \* CHARFORMAT switch which
forces the information shown in the field to take on whatever formatting is
applied to the D of DOCVARIABLE.

The variables are created by your form using the following code

ActiveDocument.Variables("varname").Value =

Also with document variables, you can have the initialize statement of your
userform populate the controls with the data held in the variable using:

[controlname].Text = ActiveDocument.Variables("varname").Value

in the Initialize() event for the form.

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP
 
M

M.P. Frosch

Thanks for the suggestion. I used the INSERT >FIELD>DOCVARIABLE menu in the
Word document to place a DOCVARIABLE ("PatientName"), and then used the
suggested command in the VBA side:
ActiveDocument.Variables("PatientName").Value = Name.txt
But nothing seems to happen. I have document update, etc going (the
substitution into ActiveDocument was working for my bookmark approach -- it
just overwrote them every time).

Looking for a bit more guidance.

Thanks.
Doug Robbins - Word MVP said:
Hi Mathew,

I would suggest that you use document variables and { DOCVARIABLE } fields
in your document rather than bookmarks. With a { DOCVARIABLE } field, you
can control the formatting by the addition of a \* CHARFORMAT switch which
forces the information shown in the field to take on whatever formatting is
applied to the D of DOCVARIABLE.

The variables are created by your form using the following code

ActiveDocument.Variables("varname").Value =

Also with document variables, you can have the initialize statement of your
userform populate the controls with the data held in the variable using:

[controlname].Text = ActiveDocument.Variables("varname").Value

in the Initialize() event for the form.

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP
M.P. Frosch said:
I am working on a VBa application that will have a long series of pages
which ask questions and accumulate information that is then used to generate
a text document. While I am working on the VBA portion, I want to try
things out in order to make sure that formating and the like is correct. I
have placed a series of named bookmarks into my template in the correct
places -- but after I run the VBA application the first time the bookmarks
are all replaced with the inserted text. Short of closing the document and
re-openning the template how do I get around this for troubleshooting.

As a related question, I know that the VBA application will only run if a
document is opened from a template but would like to find a work-around for
the situation in which the user gets halfway through responding to the
application and answering the questions. Is there a way to save the
document back as a partially completed template to be re-opened when the
user returns? If so, how do I track which bookmarks have been replaced and
therefore which userforms should be hidden?

Thanks.

Matthew
 

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