在 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 支持和反馈,获取有关如何接收支持和提供反馈的指南。