Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2005

Tip: Looking for answers? Try searching our database.

Set variable in VBA, use in document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
DoctorG - 29 Nov 2005 12:11 GMT
I wish to change the value of a variable in VBA and display its current value
in the document body. i.e. "Room <RoomVar> master controls" where <RoomVar>
changes at the push of a Button or ToggleButton.

I can declare and manage a variable in VBA but I don't know how to reference
it in the document text.
I can set up a File>Properties>Custom>Add value which I can reference in the
text, but I don't know how to reference it in VBA.

Any of the two will do. Please help.
Helmut Weber - 29 Nov 2005 12:26 GMT
Hi Doctor,

e.g. create a doc-variable with a value, like this:

ActiveDocument.Variables("MyVar").Value = "MyTest1"

Insert a doc-variable-field with a variable with name "MyVar".

Change the value of the variable, like:
ActiveDocument.Variables("MyVar").Value = "MyTest2"

Update the field:
ActiveDocument.Fields("MyVar").Update
or all fields
ActiveDocument.Fields.Update

HTH

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

DoctorG - 29 Nov 2005 13:04 GMT
Just what I needed, works fine.

Thanks Helmut!

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.