GetFirst Method

Microsoft Outlook Visual Basic

GetFirst Method

       

The GetFirst method returns the first object in the specified collection. Returns Nothing if no first object exists, for example, if there are no objects in the collection.

Note  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.

expression.GetFirst

expression  Required. An expression that returns one of the objects in the Applies To list.

Example

This Visual Basic for Applications example uses the GetFirst method to locate the first folder in the Tasks folder and then uses the Delete method to delete the folder.

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderTasks)
Set myOldFolder = myFolder.Folders.GetFirst
myOldFolder.Delete

If you use VBScript, you do not create the Application object, and you cannot use named constants. This example shows how to perform the same task using VBScript.

Set myNameSpace = Application.GetNameSpace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(13)
Set myOldFolder = myFolder.Folders.GetFirst
myOldFolder.Delete