title: Multiple toggle buttons on worksheet to trigger a macro
body: <p>I have 20 toggle buttons set-up like </p>
  
  <hr>
  
  <pre><code>Public Sub ToggleButton1_Click()
      Check_All
      If ToggleButton1.value = True Then
          ToggleButton1.BackColor = vbGreen
      Else:
          ToggleButton1.BackColor = vbRed
      End If
  End Sub
  </code></pre>
  
  <hr>
  
  <pre><code>Public Sub ToggleButton2_Click()
      Check_All
      If ToggleButton2.value = True Then
          ToggleButton2.BackColor = vbGreen
          Else:
          ToggleButton2.BackColor = vbRed
      End If
  End Sub
  </code></pre>
  
  <hr>
  
  <p>I'm attempting to get them triggered by application.onkey like:</p>
  
  <pre><code>Application.OnKey "%a", "Sheet1.ToggleButton1_Click"
  Application.OnKey "%b", "Sheet1.ToggleButton2_Click"
  </code></pre>
  
  <p>And using the Check_all for when all the buttons are "True" it'll do the following that is supposed to revert the toggle buttons back to the "False" state before it triggers another "macro".</p>
  
  <hr>
  
  <pre><code>Sub Check_All()
      Dim tb As Object
  
      For Each tb In Me.OLEObjects
          If tb.ProgId = "Forms.ToggleButton.1" Then
              If tb.Object.value &lt;&gt; True Then Exit Sub
          End If
      Next
  
      CommandButton0_Click
  End Sub
  </code></pre>
  
  <hr>
  
  <pre><code>Private Sub CommandButton0_Click()
      Dim x As Integer
  
      For x = 1 To 20
          Worksheets("Sheet1").OLEObjects("ToggleButton" &amp; x).Object.value = False
      Next x
      CommandButton3_Click
  End Sub
  </code></pre>
  
  <hr>
  
  <p>But I can't seem to get the application.onkey to work and I'm completely lost now.</p>
  
  <p>This is a system that is hooked up to programmable USB buttons and I'm really relying on the onkey to function, unless there's a better way???</p>