Browse » Home
Monday, November 11, 2013
How to Activate a Toggle Button in VBA
1. Click the 'Start' button in Windows and select the 'Microsoft Excel' from the 'All Programs' menu to open a new workbook.
2. Click the 'Tools,' 'Macro' and 'Visual Basic Editor'.
3. Click 'Insert,' then 'UserForm' to insert a user form in your workbook.
4. Add the 'ToggleButton' and 'Label' controls on the user form.
5. Double-click the 'ToggleButton' control to open the 'Code' window for the ToggleButton control.
6. 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 IfEnd Sub
7. Click the 'Run Sub/UserForm' on the 'Run' menu to activate the toggle button in your VBA control.