How to Activate a Toggle Button in VBA

Updated April 17, 2017

Microsoft Visual Basic for Applications (VBA) allows programmers to use different control objects on the user forms. The object can correspond to the box, image, scroll bar or button controls. A toggle button on a form is a control used to display a "Yes/No" value from a data source. Software developers use toggle buttons in an option group with other buttons and in dialogue boxes to accept user input. When you click a toggle button object, it appears to be pressed or pushed down. You need to obtain the value of a toggle button control in order activate the toggle button in VBA.

Click the "Start" button in Windows and select the "Microsoft Excel" from the "All Programs" menu to open a new workbook.

Click the "Tools," "Macro" and "Visual Basic Editor".

Click "Insert," then "UserForm" to insert a user form in your workbook.

Add the "ToggleButton" and "Label" controls on the user form.

Double-click the "ToggleButton" control to open the "Code" window for the ToggleButton control.

Enter the following code for the "ToggleButton1Click event:

Click the "Run Sub/UserForm" on the "Run" menu to activate the toggle button in your VBA control.

bibliography-icon icon for annotation tool Cite this Article

About the Author

Alexander Gokhfeld has been writing since 2002. He has written for the monthly business publications "AutoPublish" and "MGRealty." Gokhfeld holds certification in business intelligence infrastructure development as well as a Bachelor of Science in electric engineering from Urban Trans College.