會在 Views 集合中建立新的檢視。
語法
表情。新增 (名稱、 ViewType、 SaveOption)
詞 一個代表 Views 物件的變數。
參數
| 名稱 | 必要/選用 | 資料類型 | 描述 |
|---|---|---|---|
| Name | 必要 | String | 新檢視的名稱 |
| ViewType | 必要 | OlViewType | 新檢視的類型。 |
| SaveOption | 選用 | OlViewSaveOption | 儲存選項中指定新視圖權限:
|
傳回值
一個代表新視圖的 View 物件。
註解
如果你將 檢視 圖加入非當前資料夾的 Views 集合,必須先儲存 Views 集合物件的副本,然後再將 檢視 加入該集合物件,如以下程式碼範例所示。 這是針對現有問題的權宜之計,否則會因呼叫 View.Apply 而失敗新增 的檢視 。
Sub CalendarView()
Dim calView As Outlook.View
Dim vws As Views
Set Application.ActiveExplorer.CurrentFolder = Application.Session.GetDefaultFolder(olFolderInbox)
' Current folder is Inbox; add a View to the Calendar folder which is not the current folder
' Keep a copy of the object for the Views collection for the Calendar
Set vws = Application.Session.GetDefaultFolder(olFolderCalendar).Views
' Add the View to this Views collection object
Set calView = vws.Add("New Calendar", olCalendarView, olViewSaveOptionThisFolderEveryone)
calView.Save
' This Apply call will be fine
calView.Apply
End Sub
範例
以下 Visual Basic for Applications (VBA) 範例建立一個名為 New Table 的新視圖,並將其儲存在一個名為 objNewView的變數中。
Sub CreateView()
'Creates a new view
Dim objName As Outlook.NameSpace
Dim objViews As Outlook.Views
Dim objNewView As Outlook.View
Set objName = Application.GetNamespace("MAPI")
Set objViews = objName.GetDefaultFolder(olFolderInbox).Views
Set objNewView = objViews.Add(Name:="New Table", _
ViewType:=olTableView, SaveOption:=olViewSaveOptionThisFolderEveryone)
End Sub
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。