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 * Required. An expression that returns one of the objects in the Applies To list.
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 myOlApp As New Outlook.Application Dim myNameSpace As Outlook.NameSpace Dim myDestFolder As Outlook.MAPIFolder Dim mySourceFolder As Outlook.MAPIFolder Dim myNewFolder As Outlook.MAPIFolder Set myNameSpace = myOlApp.GetNamespace("MAPI") Set myDestFolder = myNameSpace.GetDefaultFolder(olFolderInbox).Folders("Test") Set mySourceFolder = myNameSpace.GetDefaultFolder(olFolderContacts).Folders.GetFirst Set myNewFolder = mySourceFolder.CopyTo(myDestFolder) End Sub
If you use Microsoft Visual Basic Scripting Edition (VBScript) in a Microsoft Outlook form, you do not create the Application object, and you cannot use named constants. This example shows how to delete the first folder in the default Tasks folder using VBScript code.
Set myNameSpace = Application.GetNameSpace("MAPI") Set myFolder = myNameSpace.GetDefaultFolder(13) Set myOldFolder = myFolder.Folders.GetFirst 'Prompt the user for confirmation Dim strPrompt As String strPrompt = "Are you sure you want to delete the folder?" If MsgBox(strPrompt, vbYesNo + vbQuestion) = vbYes Then myOldFolder.Delete MsgBox("Folder deleted") End If