Display the Name of Each Control on a Page

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

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

Sub CommandButton1_Click() 
 Set Controls = Item.GetInspector.ModifiedFormPages.Item("P.2").Controls 
 For i = 0 to Controls.Count - 1 
 MsgBox "MyControl.Name = " & Controls.Item(i).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.