Share via


GetFolderFromID Method

Returns a MAPIFolder object identified by the specified entry ID (if valid). This method is used for ease of transition between MAPI and OLE/Messaging applications and Microsoft Outlook.

expression**.GetFolderFromID(EntryIDFolder**, EntryIDStore)

*expression   * Required. An expression that returns a NameSpace object.

EntryIDFolder    Required String. The EntryID of the folder.

EntryIDStore    Optional Variant. The StoreID for the folder.

Example

This Visual Basic for Applications (VBA) example obtains the EntryID and StoreID for the default Tasks folder and then calls the GetFolderFromID method using these values to obtain the same folder. The folder is then displayed.

Sub GetWithID()
    Dim myOlApp As Outlook.Application
    Dim myFolder As Outlook.MAPIFolder
    Dim myEntryID As String
    Dim myStoreID As String
    Dim myNewFolder As Outlook.MAPIFolder
    Set myOlApp = CreateObject("Outlook.Application")
    Set myFolder = myOlApp.Session.GetDefaultFolder(olFolderTasks)
    myEntryID = myFolder.EntryID
    myStoreID = myFolder.StoreID
    Set myNewFolder = myOlApp.Session.GetFolderFromID(myEntryID, myStoreID)
    myNewFolder.Display
End Sub

If you use Microsoft Visual Basic Scripting Edition (VBScript) in an Outlook form, you do not create the Application object, and you cannot use named constants. This example shows how to perform the same task using VBScript code.

Set myNameSpace = Application.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(13)
myEntryID = myFolder.EntryID
myStoreID = myFolder.StoreID
Set myNewFolder = myNameSpace.GetFolderFromID(myEntryID, myStoreID)
myNewFolder.Display

Applies to | NameSpace Object

See Also | EntryID Property | StoreID Property