Storing variable data in document

M

Mike Starr

I've created a template that presents a user form. The form has a text field
that the user enters a filename. I use this filename and another variable to
construct the name that the document will be saved as.

I need to store the user-entered name in the saved document along with the
other variable so that if a user opens a previously saved document based on
this template, I can retrieve those variables.

How does one store a variable so that it will persist in the saved document
for later retrieval??

Thanks

Mike
 
H

Helmut Weber

Hi Mike,

you may use a document variable,
like this:

Dim sVar As String
sVar = "testvar"
With ActiveDocument.Variables
.Item("MyName").Value = sVar
MsgBox .Item("MyName").Value ' testing
End With

Creates the variable, if doesn't exist,
and sets the value, otherwise, just sets the value.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
M

Mike Starr

Thanks to both Helmut and ML... you've pointed me in the right direction.
Now that I know what to look for, I've found the appropriate topics in the
VBA help file.

Mike
 

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