Views.Add 方法 (Outlook)
會在 Views 集合中建立新的檢視。
語法
運算式。新增 (名稱、 ViewType、 SaveOption)
表達 代表 Views 物件的變數。
參數
名稱 | 必要/選用 | 資料類型 | 描述 |
---|---|---|---|
Name | 必要 | String | 新檢視的名稱 |
ViewType | 必要 | OlViewType | 新檢視的類型。 |
SaveOption | 選用 | OlViewSaveOption | 指定新檢視許可權的儲存選項:
|
傳回值
代表新檢 視的 View 物件。
註解
如果您將 View 新增至不是目前資料夾之資料夾的 Views 集合,則必須先儲存 Views 集合物件的複本,然後將 View 新增至這個集合物件,如下列程式碼範例所示。 這是現有問題的因應措施,否則會導致呼叫 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 支援與意見反應。