Macro Execute Counter?


Posted by RoB on August 16, 2001 11:39 AM

Is there a way to put a counter on how many times a macro is executed?

What I want to do is: have a macro that is linked to a button. I want this button to be clicked ONE time, then disappear after that, so that the user cant click it anymore (this macro will save the file "saveas")

Thanks.

Posted by Robb on August 16, 2001 2:38 PM

Rob

Just set the Enabled property of the button to False at the end of its code. You could also set the Visible property to False - this would mean the user would no longer be able to see the button.

I don't know where the button is, but if it were on a worksheet, the code would be:

Worksheets("Sheet1").CommandButton1.Enabled = False
and/or
Worksheets("Sheet1").CommandButton1.Visible = False

Does this help?

Regards

Posted by RoB on August 16, 2001 3:26 PM

Yes, the button is on sheet "Application". I tried the code you gave me (Worksheets("Sheet1").CommandButton1.Enabled = False) but it gives an error when i run the macro. (Object doesn't support this property or method). Do I need to name the button or something?

Thanks



Posted by Robb on August 17, 2001 4:01 AM

Rob

You need to identify the button and the sheet in the code. You could have referred to it as Worksheets("Application") but Me does just as well.
As for the button - you need to identify its name. CommandButton name should be obvious from the Code page for the worksheet (the code page in which you have the code for the button) - just use the same name as appears in the "Click" event name.

Code line may be simply:

Me.CommandButton1.Visible = False '[Substitute whatever the name of the button is for "CommandButton1

If you are not sure, just set it to any of the bottons on the page. If the wrong button disappears, just reverse the procedure to:
Me.CommandButton1.Visible = True
to get it back again. Then try another one.

Does this help?

Regards