How to: Display the Name of Each Control on a Page

Outlook Developer Reference

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