Run once macro

J

James

Hello NG,
I have a macro that is associated with a check box from the "forms" tools,
and if it is clicked then the "Run macro on Entry" of the check box.
If someone changes their mind and deselects chbox and then selects it again
the macro runs again.

How can I get the macro to only run once.
I've tried to create a flag and set it to 1 if the macro has already run,
but that doesn't seem to work for me,

any suggestions.
James



'Code begins here============
Private Sub Document_Open()
Dim wdFlag As Integer
wdFlag = 0
End Sub

Sub Color()
'
' Color Macro
' Created: Nov. 9th 2004
' Author: James
' Purpose: Informs customer of printer purchase options
'

If wdFlag = 0 Then
Selection.EndKey Unit:=wdStory
Selection.Font.Color = wdColorDarkBlue
Selection.TypeText Text:= _
"We can help you purchase an inkjet printer at a substantial "
Selection.TypeText Text:="discount!" & Chr(11) & _
"Please call Liz at 555-1234 for more information!"
wdFlag = 1
Else
Exit Sub
End If

End Sub

'Code ends here===========
 
J

Joost Verdaasdonk

Hi,

Put something in the document you can delete after macro
execution! e.g.: Bookmark, doc variable, etc....

Little Example for you're code: (using bookmark)
Sub Test()
If ActiveDocument.Bookmarks.Exists("bmCheck") Then
'Do you're stuff
ActiveDocument.Bookmarks("bmCheck").Delete
End If
End Sub

Enjoy,
Groetjes,
Joost Verdaasdonk
 
J

James

Joost Verdaasdonk,
Thanks for the help, I am going to put this to work first thing Monday
morning
James
 
G

Gal Zilberman

Or you can just add a global variable
Example
private Flag as boolean

Sub Test()
if Flag =True then
' Don't run the macro
else
'Do what you want
Flag =True
end if
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top