Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

Run once macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James - 13 Nov 2004 19:11 GMT
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===========
Joost Verdaasdonk - 13 Nov 2004 20:52 GMT
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
James - 15 Nov 2004 02:13 GMT
Joost Verdaasdonk,
Thanks for the help, I am going to put this to work first thing Monday
morning
James

> Hi,
>
[quoted text clipped - 12 lines]
> Groetjes,
> Joost Verdaasdonk
Gal Zilberman - 15 Nov 2004 10:58 GMT
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

> Joost Verdaasdonk,
> Thanks for the help, I am going to put this to work first thing Monday
[quoted text clipped - 17 lines]
>> Groetjes,
>> Joost Verdaasdonk

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.