How to prevent macro being run when another one is running

#1
I have some VBA macros set up as toolbar buttons. When one of the macros is running, however, its possible to press another toolbar button. That causes the running macro to stop running, and starts the other one. That is a problem... I want to prevent macros from running until the running one has done its thing.

Is there an easy/clean way to do it? The two ways I thought of are to 1) set IntelliCAD.Visible to False when starting a macro and True when ending it, 2) use IntelliCAD.RunCommand to undefine the vbarun, -vbarun commands at the beginning of the macros (and redefine them when done). The first one isn't an option to me, and the second one could pose problems if the macro stops before redefining.

Has anyone run across this problem? Any other solutions? I was using the code below to test it.

Public Sub test()
Dim i As Integer, dStart As Double
For i = 1 To 1000
dStart = Timer
Do While Timer < dStart + 0.1 ' wait 0.1 seconds
DoEvents
Loop
Debug.Print i
Next i
End Sub

Thanks...

Kenn

#2
kenn1,

I guess it might depend on what you are doing with each routine and how it is coded.

Set a global flag and check it when initializing each routine?

Read/write a registry setting (global flag)?

Need to post more information.

ssc

#3
Thanks for the response. It looks like running a second macro immediately stops the first one, so setting a global flag in VBA or using a reading/writing a registry setting with VBA wouldn't work. When the second macro read the flag to see if it was ok to proceed, the first macro would already have been stopped. The global flag/registry setting would have to be checked by the code for the toolbar button. I think that setting one of the USER* variables to a certain value would be the easiest way. I may just stick with undefining/redefining the vbarun, -vbarun commands. It basically serves the same purpose and prevents someone from using the Tools > VB > Macros option.