Count property example

The following example displays the Count property of the Controls collection for the form, and the Count property identifying the number of pages and tabs of each MultiPage and TabStrip.

To use this example, copy this sample code to the Declarations portion of a form. The form can contain any number of controls, with the following restrictions:

  • Names of MultiPage controls must start with MultiPage.
  • Names of TabStrip controls must start with TabStrip.

Note

You can add pages to a MultiPage or add tabs to a TabStrip. In Windows, double-click the control, and then right-click in the tab area of the control and choose New Page from the shortcut menu.

Private Sub UserForm_Initialize() 
 Dim MyControl As Control 
 
 MsgBox "UserForm1.Controls.Count = " _ 
 & Controls.Count 
 
 For Each MyControl In Controls 
 If (MyControl.Name Like "MultiPage*") Then 
 MsgBox MyControl.Name _ 
 & ".Pages.Count = " _ 
 & MyControl.Pages.Count 
 ElseIf (MyControl.Name Like "TabStrip*") Then 
 MsgBox MyControl.Name & ".Tabs.Count = " _ 
 & MyControl.Tabs.Count 
 End If 
 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.