Returning an Object from a Collection

Returning an Object from a Collection (Publisher)

Office 2013 and later
GitHub-Mark-64px

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

The Item method returns a single object from a collection. The following example sets a variable to a Page object that represents the first page in the Pages collection.

Sub SetFirstPage() 
 Dim pgFirst As Page 
 Set pgFirst = ActiveDocument.Pages.Item(1) 
End Sub

The Item method is the default method for most collections, so you can write the same statement more concisely by omitting the Item keyword.

Sub SetFirstPage() 
 Dim pgFirst As Page 
 Set pgFirst = ActiveDocument.Pages(1) 
End Sub
Show:
© 2016 Microsoft