GetFirst Method

Folders.GetFirst Method (Outlook)

Office 2013 and later

Contribute to this content

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

Returns the first object in the Folders collection.

expression .GetFirst

expression A variable that represents a Folders object.

Return Value

A Folder object that represents the first object contained by the collection.

Returns Nothing if no first object exists, for example, if there are no objects in the collection.To ensure correct operation of the GetFirst, GetLast, GetNext, and GetPrevious methods in a large collection, call GetFirst before calling GetNext on that collection and call GetLast before calling GetPrevious. To ensure that you are always making the calls on the same collection, create an explicit variable that refers to that collection before entering the loop.

This Visual Basic for Applications (VBA) example uses the GetFirst method to locate the first folder in the Contacts folder and then copies the folder to the Test folder. Before running this example, you need to make sure the necessary folders exist in the default Contacts and Inbox folders.

Sub CopyItems() 
 Dim myNameSpace As Outlook.NameSpace 
 Dim myDestFolder As Outlook.Folder 
 Dim mySourceFolder As Outlook.Folder 
 Dim myNewFolder As Outlook.Folder 
 Set myNameSpace = Application.GetNamespace("MAPI") 
 Set myDestFolder = myNameSpace.GetDefaultFolder(olFolderInbox).Folders("Test") 
 Set mySourceFolder = myNameSpace.GetDefaultFolder(olFolderContacts).Folders.GetFirst 
 Set myNewFolder = mySourceFolder.CopyTo(myDestFolder) 
End Sub
© 2016 Microsoft