Share via


Folders.GetFirst Method (Outlook)

Returns the first object in the Folders collection.

Syntax

expression .GetFirst

expression A variable that represents a Folders object.

Return Value

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

Remarks

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.

Example

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

See Also

Concepts

Folders Object Members

Folders Object