Count Property
Applies To
Controls collection, Pages collection, Tabs collection.
Description
Returns the number of objects in a collection.
Syntax
object.Count
The Count property syntax has these parts:
Part | Description |
|
object | Required. A valid object. |
Remarks
The Count property is read-only.
Note that the index value for the first page or tab of a collection is zero, the value for the second page or tab is one, and so on. For example, if a MultiPage contains two pages, the indexes of the pages are 0 and 1, and the value of Count is 2.
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. Double-click on 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
Next
End Sub