Table of contents
Collapse the table of content
Expand the table of content

Count Property Example

office 365 dev account|Last Updated: 6/12/2017
1 Contributor

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, 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 

End Sub
© 2018 Microsoft