Document variables

A

Andrew

I am having problems assigning the value of document
variables to a text box in VBA. It seams that the active
document index for a document variable changes every time
I create a document variable. For example, when I start
creating variables the first one is usually indexed as 1
then the next would be 2 and then I find that it jumps a
few, then when I create a few more variables the active
document index goes wild and I am unable to access the
variables.

The question: How do I find out what active document
variable index number each of the document variables is
at and is there another way of getting the value of the
document variables in VBA.

Before the document variable idea, I was using the
includeText field to map to external files. The problem
with the includeText field feature is that it is not
portable. What I would like to do is make the path
changeable in VBA.

If anyone can help, it would be appreciated.

Thanks in advance.
 
S

Steve Lang

Hi Andrew,

Why not use the Document Variable name instead of the index? It has to be
unique and can't spontaneously change.

Although, if you want to find all the index numbers and names you can:

Dim myVar as variable
For each myVar in Activedocument.Variables
debug.print myvar.Index, myvar.Name
Next

HTH and have a great day!

Steve
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < Andrew > écrivait :
In this message, < Andrew > wrote:

|| I am having problems assigning the value of document
|| variables to a text box in VBA. It seams that the active
|| document index for a document variable changes every time
|| I create a document variable. For example, when I start
|| creating variables the first one is usually indexed as 1
|| then the next would be 2 and then I find that it jumps a
|| few, then when I create a few more variables the active
|| document index goes wild and I am unable to access the
|| variables.
||
|| The question: How do I find out what active document
|| variable index number each of the document variables is
|| at and is there another way of getting the value of the
|| document variables in VBA.
||
|| Before the document variable idea, I was using the
|| includeText field to map to external files. The problem
|| with the includeText field feature is that it is not
|| portable. What I would like to do is make the path
|| changeable in VBA.
||

Why are you using the variable index? Since you are the one creating the
variables, you should know their names. Use their names.
In the document, where you want the variable value to appear, use a
DOCVARIABLE field.
In VBA, use
ActiveDocument.Variable(MyVariableName).Value

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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