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.
- Skill level:
- Moderately Easy
Other People Are Reading
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:
Private Sub ToggleButton1_Click() If ToggleButton1.Value = True Then ' Set UserForm background to Red. Me.BackColor = RGB(255, 0, 0) Else ' Set UserForm background to Blue. Me.BackColor = RGB(0, 0, 255) End If End Sub
Click the "Run Sub/UserForm" on the "Run" menu to activate the toggle button in your VBA control.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for