共用方式為


Outlook) (Store.GetRootFolder 方法

會傳回 Folder 物件,代表 Store的根層級資料夾。 唯讀。

語法

expressionGetRootFolder

表達 代表 Store 物件的變數。

傳回值

Folder 物件,表示位於該 Store 根目錄的資料夾。

註解

使用 GetRootFolder 方法來列舉 Store根資料夾的子資料夾。 不同于 NameSpace.Folders 包含目前設定檔中所有存放區的所有資料夾, Store.GetRootFolder.Folders 可讓您列舉目前設定檔中指定 Store 物件的所有資料夾。

存放區根資料夾的 Parent 屬性會傳回字串 「Mapi」。

Exchange 公用資料夾儲存區的根資料夾就是 [公用資料夾] 資料夾。 呼叫 會 Application.Session.GetDefaultFolder(olPublicFoldersAllPublicFolders) 傳回此資料夾。

如果服務提供者不支援根資料夾,GetRootFolder 就會傳回錯誤。

範例

下列 Microsoft Visual Basic for Applications (VBA) 程式碼範例會從工作階段之 Stores 集合中每個 Store 的根層級資料夾開始,並列舉該工作階段之所有儲存區上的所有資料夾。

Sub EnumerateFoldersInStores() 
 
 Dim colStores As Outlook.Stores 
 
 Dim oStore As Outlook.Store 
 
 Dim oRoot As Outlook.Folder 
 
 
 
 On Error Resume Next 
 
 Set colStores = Application.Session.Stores 
 
 For Each oStore In colStores 
 
 Set oRoot = oStore.GetRootFolder 
 
 Debug.Print (oRoot.FolderPath) 
 
 EnumerateFolders oRoot 
 
 Next 
 
End Sub 
 
 
 
Private Sub EnumerateFolders(ByVal oFolder As Outlook.Folder) 
 
 Dim folders As Outlook.folders 
 
 Dim Folder As Outlook.Folder 
 
 Dim foldercount As Integer 
 
 
 
 On Error Resume Next 
 
 Set folders = oFolder.folders 
 
 foldercount = folders.Count 
 
 'Check if there are any folders below oFolder 
 
 If foldercount Then 
 
 For Each Folder In folders 
 
 Debug.Print (Folder.FolderPath) 
 
 EnumerateFolders Folder 
 
 Next 
 
 End If 
 
End Sub

另請參閱

Store 物件

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應