How to Activate a Toggle Button in VBA

Written by alexander gokhfeld
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Activate a Toggle Button in VBA
The toggle controls help programmers design option forms in VBA applications. (Jupiterimages/Photos.com/Getty Images)

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

Instructions

  1. 1

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

  2. 2

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

  3. 3

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

  4. 4

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

  5. 5

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

  6. 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 If
    
    
    
      End Sub
    
  7. 7

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

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.