Name Property Example

The following example displays the Name property of each control on a form. This example uses the Controls collection to cycle through all the controls placed directly on the Userform.

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains a CommandButton named CommandButton1 and several other controls.

Private Sub CommandButton1_Click()
    Dim MyControl As Control

    For Each MyControl In Controls
        MsgBox "MyControl.Name = " & MyControl.Name
    Next
End Sub