malte
malte

Reputation: 559

Evaluating ToggleButton on specific worksheet

How can I evaluate the status of a toggle button on a specific worksheet?

If my code is stored with the specific worksheet, I can just refer to the name of the button:

Private Sub ToggleButton1_Click()
If ToggleButton1.Value = True Then
    Debug.Print "true"
Else
    Debug.Print "false"
End If
End Sub

However, if my code is stored in a module the above method does not worked. I have tried the following but it also does not work:

Public Sub Check_Button()
If Sheets("sheet1").OLEObjects("ToggleButton1").Value = True Then
    Debug.Print "true"
Else
    Debug.Print "false"
End If
End Sub

Upvotes: 0

Views: 1013

Answers (1)

quantum285
quantum285

Reputation: 1032

Simply:

Public Sub Check_Button()
If Sheets("sheet1").ToggleButton1.Value = True Then
    Debug.Print "true"
Else
    Debug.Print "false"
End If
End Sub

And whilst it's probably not good practice it's worth mentioning you can lose the ".Value" as such:

If Sheets("sheet1").ToggleButton1 = True Then

Upvotes: 1

Related Questions