Part of your problem is you are deleting variables by setting them equal to ""
Demo:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
With ActiveDocument
.Variables("Test").Value = "Test"
MsgBox "This document contains: " & .Variables.Count & " variable"
'Setting a name variable value to "" deletes the variable
.Variables("Test").Value = ""
On Error Resume Next
MsgBox ActiveDocument.Variables("Test").Value
MsgBox "This document contains: " & .Variables.Count & " variables"
End With
End Sub
You need to have something in the variable even if it is just " " If you look at the code in Graham's example, you will see that is what he did
Yes, provide other users allow macros to run in their documents, if you set up this way then it should work for everyone.
|