Compartilhar via


GetDefaultFolder Method

Returns a MAPIFolder object that represents the default folder of the requested type for the current profile, for example, obtains the default Calendar folder for the user who is currently logged on.

Note   To return a specific non-default folder, use the Folders collection.

expression**.GetDefaultFolder(FolderType)**

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

OlDefaultFolders

OlDefaultFolders can be one of these OlDefaultFolders constants.
olFolderCalendar
olFolderContacts
olFolderDeletedItems
olFolderDrafts
olFolderInbox
olFolderJournal
olFolderJunk
olFolderNotes
olFolderOutbox
olFolderSentMail
olFolderTasks
olPublicFoldersAllPublicFolders
olFolderConflicts
olFolderLocalFailures
olFolderServerFailures
olFolderSyncIssues

Example

This Visual Basic for Applications (VBA) example uses the CurrentFolder property to change the displayed folder to the user's default Calendar folder.

Sub ChangeCurrentFolder()
    Dim myolApp As Outlook.Application
    Dim myNamespace As Outlook.NameSpace
    Set myolApp = CreateObject("Outlook.Application")
    Set myNamespace = myolApp.GetNamespace("MAPI")
    Set myolApp.ActiveExplorer.CurrentFolder = _
    myNamespace.GetDefaultFolder(olFolderCalendar)
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 perform the same task using VBScript code.

Set myNameSpace = Application.GetNameSpace("MAPI")
Set Application.ActiveExplorer.CurrentFolder = _
myNameSpace.GetDefaultFolder(9)

This VBA example returns the first folder in the Tasks Folders collection.

Sub DisplayATaskFolder()
Dim myolApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myTasks As Outlook.MAPIFolder
Dim myFolder As Outlook.MAPIFolder
Set myolApp = CreateObject("Outlook.Application")
Set myNamespace = myolApp.GetNamespace("MAPI")
Set myTasks = myNamespace.GetDefaultFolder(olFolderTasks)
Set myFolder = myTasks.Folders(1)
myFolder.Display
End Sub

Applies to | NameSpace Object

See Also | Folders Object | Folders Property