共用方式為


將自訂資料夾新增至群組,並預設以重迭模式顯示

您可以使用NavigationGroup物件之NavigationFolders集合的Add方法,將自訂流覽資料夾新增至 Microsoft Outlook 中的流覽群組。 Add方法會接受Folder物件參考,而自訂導覽資料夾會與該物件相關聯。

如果自訂流覽資料夾與行事曆資料夾相關聯,您也可以使用NavigationFolder物件的IsSideBySide屬性來判斷自訂流覽資料夾的內容是否以並排或重迭模式顯示。

此範例會為公司事件建立新的行事曆資料夾,並為新的資料夾新增自訂的巡覽資料夾,然後設定自訂巡覽資料夾使其依預設以重疊模式來顯示。

此範例會執行下列動作:

  1. 此範例會先使用 NameSpace 物件的 GetDefaultFolder 方法,取得目前使用者之 [行事曆] 預設資料夾的 Folder 物件參照。

  2. 然後在 [行事曆] 預設資料夾的 Folders 集合中,建立名稱為 "Company Events" 的新 Folder 物件 (代表新的行事曆資料夾)。

  3. 本範例接著會取得對作用中瀏覽器之 NavigationPane 物件的參照,並且使用 NavigationModules 集合的 GetNavigationModule 方法來取得 CalendarModule 物件參照。

  4. 然後,它會使用CalendarModuleNavigationGroups集合的GetDefaultNavigationGroup方法,取得My Calendars流覽群組的NavigationGroup物件參照。

  5. 然後根據範例先前所建的 Folder 物件,以巡瀏群組之 NavigationGroups 集合的 Add 方法,將 NavigationFolder 物件新增至巡瀏群組。

  6. 然後,此範例會將NavigationPane物件的CurrentModule屬性設定為CalendarModule物件參照,以確保 [行事曆] 流覽模組目前顯示在功能窗格中。

  7. 最後,範例會設定巡瀏資料夾:

    • 本範例會將 IsSelected 屬性設定為 True ,將它顯示在作用中瀏覽器內。
  • 然後,本範例會將 IsSideBySide 屬性設定為 False ,如此就會依預設以重疊模式加以顯示。
Private Sub CreateCompanyEventsFolder() 
 Dim objNamespace As NameSpace 
 Dim objCalendar As Folder 
 Dim objFolder As Folder 
 
 Dim objPane As NavigationPane 
 Dim objModule As CalendarModule 
 Dim objGroup As NavigationGroup 
 Dim objNavFolder As NavigationFolder 
 
 On Error GoTo ErrRoutine 
 
 ' First, retrieve the default calendar folder. 
 Set objNamespace = Application.GetNamespace("MAPI") 
 Set objCalendar = objNamespace.GetDefaultFolder(olFolderCalendar) 
 
 ' Create a new calendar folder named "Company Events". 
 Set objFolder = objCalendar.Folders.Add("Company Events", olFolderCalendar) 
 
 ' Get the NavigationPane object for the 
 ' currently displayed Explorer object. 
 Set objPane = Application.ActiveExplorer.NavigationPane 
 
 ' Get the calendar module from the Navigation Pane. 
 Set objModule = objPane.Modules.GetNavigationModule(olModuleCalendar) 
 
 ' Get the "My Calendars" navigation group from the 
 ' calendar module. 
 With objModule.NavigationGroups 
 Set objGroup = .GetDefaultNavigationGroup(olMyFoldersGroup) 
 End With 
 
 ' Add a new navigation folder for the "Company Events" 
 ' folder in the "My Calendars" navigation group. 
 Set objNavFolder = objGroup.NavigationFolders.Add(objFolder) 
 
 ' Set the navigation folder to be displayed in overlay mode 
 ' by default. The IsSelected property can't be set to True 
 ' unless the CalendarModule object is the current module 
 ' displayed in the Navigation Pane. 
 Set objPane.CurrentModule = objModule 
 objNavFolder.IsSelected = True 
 objNavFolder.IsSideBySide = False 
 
EndRoutine: 
 On Error GoTo 0 
 
 Set objNavFolder = Nothing 
 Set objFolder = Nothing 
 Set objGroup = Nothing 
 Set objModule = Nothing 
 Set objPane = Nothing 
 Set objNamespace = Nothing 
 
 Exit Sub 
 
ErrRoutine: 
 MsgBox Err.Number & " - " & Err.Description, _ 
 vbOKOnly Or vbCritical, _ 
 "CreateCompanyEventsFolder" 
End Sub

支援和意見反應

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