View Single Post
 
Old 10-02-2014, 04:30 PM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote