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

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Kent Petty

New Member
Joined
Jan 3, 2005
Messages
19
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
 

CraigM

Active Member
Joined
Feb 27, 2003
Messages
320
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.
 

Kent Petty

New Member
Joined
Jan 3, 2005
Messages
19

ADVERTISEMENT

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
 

one_more_cave_dweller

Board Regular
Joined
Sep 27, 2004
Messages
118
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!
 

CraigM

Active Member
Joined
Feb 27, 2003
Messages
320
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.
 

Forum statistics

Threads
1,147,848
Messages
5,743,525
Members
423,801
Latest member
paulj4177

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
Top