Changing the toggle button setting during another macro i.e., without physically clicking it

dougmarkham

Active Member
Joined
Jul 19, 2016
Messages
252
Office Version
  1. 365
Platform
  1. Windows
Hi Folks,

I have a Toggle button on one of my sheets called: LocationFormat.
It works a treat.

My question is: can I add VBA code to another macro in order to turn off or turn on the Toggle button, i.e. so it automatically changes state when I run another macro?

Kind regards,

Doug.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi Jaafar,

I tried your code:
ToggleButton1= Not ToggleButton1
It's my only toggle button , but this code didn't work and also didn't cause run-time error.

Also, I substituted using my Toggle button name:
LocationFormat = Not LocationFormat

This didn't bring up an error, but didn't turn off the button.
I have more than one toggle button in the workbook.

Any ideas?

Kind regards,

Doug
 
Upvote 0
How about ?:
VBA Code:
 LocationFormat.Value = Not LocationFormat.Value
 
Upvote 0
Hi Jaafar,

Thanks for trying. This causes run-time error 424: no object etc.
In the mean-time, I kept searching and got lucky on a Google search: found this which seems to work

VBA Code:
Dim Ctrl As OLEObject
Worksheets("MyWorksheet").OLEObjects("LocationFormat").Object.Value = False

Seems to get around the run-time error issue.

Thanks again for your help!

Kind regards,

Doug.
 
Upvote 0

Forum statistics

Threads
1,214,634
Messages
6,120,659
Members
448,975
Latest member
sweeberry

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