Bewerken

Delen via


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

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.