Make a simple button behave like a toggle button?

leonlai

Board Regular
Joined
Mar 22, 2019
Messages
77
Hi, everybody

Suppose I have a simple button (not a toggle button).

I want it to run the macro "Macro1" when I click on it the first time, and run "Macro2" when I click it a second time.

If I click it a third time, it will run "Macro1" again...

I want something simple, because I will later need to translate the macros into VB .NET.

How can this be done?

Thanks.

Leon
 
Re: How can we make a simple button behave like a toggle button?

Hi, Rick

What kind of button is it... one found on a UserForm or, if on a worksheet, is it a Forms button or an ActiveX button?

For the moment, I am using a Rectangular shape on my worksheet and it is assigned a macro.
I could just have used a Forms Button or an ActiveX button.

However, I just want to learn the idea, because I will ultimately convert all my VBA code to VB.NET (using Visual Studio and Add-In Express, which is similar to VSTO).

So, whether you give me the code for Rectangle, or FormsButton, or ActiveX button, will be OK for me.
It's just for learning. I will then have to adapt the idea when I develop my add-in using VB.NET.

Best Regards,
Leon
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Re: How can we make a simple button behave like a toggle button?

Hi, NdNoviceHlp

Thanks for the code. It works, and I can incorporate it in my development.

Best Regards,
Leon
 
Upvote 0
Re: How can we make a simple button behave like a toggle button?

Hi, Rick

NdNoviceHlp has already answered the question.


Best Regards,
Leon
 
Upvote 0
Re: How can we make a simple button behave like a toggle button?

You are welcome Leon. Thanks for posting your outcome. The code posted was for a userform command button (for some unknown reason as Rick indicated) but the logic can be easily adapted for whatever similar use. Have a nice day. Dave
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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