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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Errors accessing word document variable parameters

Status
Not open for further replies.

DiverMarv

Programmer
Jul 13, 2000
14
US
Hello all.

I am using a third-party solution to generate word documents on our server. For control purposes, I am also adding two document variables to the document. Now I am writing VBA that will be included with all the word documents our clients use. I want to "check" to see if the variables exist in the document, and if they do, provide a prompt to synchronize with the server. I have the synchronize part done, I'm having difficulty with the looping through the document variables part. Here is the snippet of code taht is failing:

Sub RunScript()
Dim v As Variable
Dim vExists As Boolean
vExists = False
For Each v In ActiveDocument.Variables
If v.Name = "serverUri" Then
vExists = True
Exit For
End If
Next v
If vExists Then
SaveDocument
End If
End Sub

Where there are no variables present, it works just fine. Well, nothing happens which is just fine. But if the variables are present, the above script fails on the "v.Name" line with the following error: Runtime error '5835': Object has been deleted.

If I replace that line with MsgBox "show me", then I get two message boxes appropriate for teh existance of the two variables. But v.Name, and v.Value doesn't seem to work.

I'm sure I'm missing something simple.

Thanks
 
The document.variables collection does not have either the name or value property, but it does have the item method and the count property. So, I suppose you'll have to use activedocument.variables.item(i).name, where i=1 to activedocument.variables.count

_________________
Bob Rashkin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top