命名空间 GetDefaultFolder 方法 (Outlook)NameSpace.GetDefaultFolder method (Outlook)

返回一个**Folder** 对象, 该对象代表当前配置文件所请求的类型的默认文件夹;例如, 获取当前登录的用户的默认 "日历" 文件夹。Returns a Folder 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.

语法Syntax

expressionexpression. GetDefaultFolder( _FolderType_ )

_表达式_一个代表NameSpace对象的变量。expression A variable that represents a NameSpace object.

参数Parameters

名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
FolderTypeFolderType 必需Required OlDefaultFoldersOlDefaultFolders 要返回的默认文件夹类型。The type of default folder to return.

返回值Return value

一个代表当前配置文件的所请求类型的默认文件夹的folder对象。A Folder object that represents the default folder of the requested type for the current profile.

备注Remarks

若要返回特定的非默认文件夹, 请使用**Folders** 集合。To return a specific non-default folder, use the Folders collection.

如果所请求的类型的默认文件夹不存在,具体取决于类型,Outlook 可能会创建并返回该文件夹,或可能会引发错误。If the default folder of the requested type does not exist, depending on the type, Outlook may create and return the folder, or may raise an error. 例如, 如果将olFolderManagedEmail指定为_FolderType_ , 但尚未部署托管文件夹组, 则 Microsoft Outlook 将引发错误。For example, if olFolderManagedEmail is specified as the FolderType but the Managed Folders group has not been deployed, Microsoft Outlook raises an error.

示例Example

本 Visual Basic for Applications (VBA) 示例使用**CurrentFolder** 属性将显示的文件夹更改为用户的默认 "日历" 文件夹。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 myNamespace As Outlook.NameSpace 
 
 
 
 Set myNamespace = Application.GetNamespace("MAPI") 
 
 Set Application.ActiveExplorer.CurrentFolder = _ 
 
 myNamespace.GetDefaultFolder(olFolderCalendar) 
 
End Sub

本 VBA 示例返回任务 Folders 集合中的第一个文件夹。This VBA example returns the first folder in the Tasks Folders collection.

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

另请参阅See also

命名空间对象NameSpace Object

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.