GetFolderFromID Method Example

GetFolderFromID Method Example

This Visual Basic for Applications example obtains the EntryID and StoreID for a subfolder within the Tasks Folders collection and then calls the GetFolderFromID method using these values to obtain the same subfolder. The folder is then displayed.

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNameSpace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderTasks)
Set myOwnFolder = myFolder.Folders(1)
myEntryID = myOwnFolder.EntryID
myStoreID = myOwnFolder.StoreID
Set myNewFolder = myNameSpace.GetFolderFromID(myEntryID, myStoreID)
myNewFolder.Display

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 myOwnFolder = myFolder.Folders(1)
myEntryID = myOwnFolder.EntryID
myStoreID = myOwnFolder.StoreID
Set myNewFolder = myNameSpace.GetFolderFromID(myEntryID, myStoreID)
myNewFolder.Display