Control

one_more_cave_dweller

Board Regular
Joined
Sep 27, 2004
Messages
118
:rolleyes:
I have 2 macros in a workbook that are each ran by clicking a button. Is there a way to not allow the user to run one macro until the other has ran?

Thanks :pray:
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You could set the default "visible" property of the 2nd button to "False", then have excection of the first button cause the "visible" property of the second button to be set to true. I.e.:

Private Sub CommandButton1_Click()
CommandButton2.Visible = True

End Sub

Cheers,

Kent in Alaska
 
Upvote 0
Or the same but with the Enabled property, so that the button is still visible, but is "greyed out" and can't be clicked. Depends how you want it to work.
 
Upvote 0
Good point Craig. I'm normally working with applications that are used on slate computers out of doors, so sometimes it's hard to tell if a button or checkbox is greyed out due to the bright light conditions....I tend to use the visible property instead as a result.

Cheers,

Kent
 
Upvote 0
It is a button from the forms toolbar. I'm very new to this, could you please elaborate on where I would ad the code. I think greying out the button would work best for me.

Thank you so much for your help!
 
Upvote 0
OK. To do this you're going to have to use the button from the controls toolbar. These are more complicated, but correspondingly more useful.

Add two buttons from the controls toolbar. These will have the default captions CommandButton1 and 2 respectively. Right click CommandButton1 and click “Properties”. This is the list of properties of the button you can change. Change the “Caption” property to whatever you want to appear on the button. Do the same for CommandButton2, but this time also change the “Enabled” property to false.

Now for the code. Right click CommandButton1 and select “View Code”. The VBE will open and you should see this:

Private Sub CommandButton1_Click()

End Sub

Between these two lines of code type the following (replace “YourMacroName” with the name of your macro):

Call YourMacroName
CommandButton2.Enabled = True

Close the VBE. Then, in Excel, Exit Design Mode by clicking button on the controls toolbar with the blue set square, ruler and pencil. You must always enter Design Mode to alter controls.

It should be all ready to go. You’ll probably already realise how much more useful these can be than the “Form” buttons.
 
Upvote 0

Forum statistics

Threads
1,222,072
Messages
6,163,747
Members
451,855
Latest member
mcook36155

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top