GetDefaultFolder Method

Microsoft Outlook Visual Basic

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.

FolderType    Required OlDefaultFolders. The type of default folder to return.

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

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