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
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