How to reference properties of a userForm to a sub in excel?

Asked

Viewed 32 times

0

I created a form in vba (excel) and in this form contains a checkbox, I would like to trigger a given command if the checkbox is marked, however the code to be triggered is in a module sub separate from the userForm.

I would like to know how I can reference the checkbox. Below is the code to be triggered:


    If (ccbDeleteForms = True) Then
        plRelatorio.Activate
        Rows("10418:40000").Select
        Selection.Delete
    End If

  • 1

    Problem solved, just use (form name).(property to be referenced) For example, highwaySelection.ccbDeleteForms.locked = false

1 answer

-1

You solved it, but I have a more generic solution:

If you pass the Checkbox as a parameter, you will not need to reference userform in your method and so you can pass any object.

Sub ChecarCkb(obj As Object)
    If TypeName(obj) = "CheckBox" Then
        If obj Then MsgBox "Objeto está selecionado"
    End If
End Sub

Private Sub CheckBox1_Click()
    'Aqui você passa o objeto
    Call ChecarCkb(CheckBox1)
End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.