Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I just want to fill in a docvariable with vba in word 2000

Status
Not open for further replies.

f1car

Technical User
Apr 2, 2001
69
US

Sub GetSetDocVars()

Dim fName As String
fName = "Jeff Smith"
' Set contents of variable "fName" in a document using a document
' variable called "FullName".
ActiveDocument.Variables.Add Name:="FullName", Value:=fName
' Retrieve the contents of the document variable.
MsgBox ActiveDocument.Variables("FullName").Value

End Sub
NOTE : The following error message appears if the Variable name is already set in the document:
Run-Time Error "5903": The Variable name already exists.
You must delete the name or just reset the value argument.

"Now I get variable already exists" I've seen people do this before but I've never seens the working code?
 
I do not use ADD. I just assign it.

ActiveDocument.Variables(strVariableName) = strWValue

By the way. If you asign "", the variable is deleted from the collection and if it is used in a document you get a "missing" on the document instead of "" so I always initialize them to " ". Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top