View 对象

         
多个对象
View
NameSpace

View 对象使用户可以创建自定义的视图,以便能更好地排序、分组及最终查看多种类型的数据。多种不同的视图类型提供了创建和维护重要数据所需的灵活性。

视图是通过 View 对象的 XML 属性定义和自定义的。XML 属性使用户可以创建和设置自定义的 XML 方案,方案定义了视图的各种功能。

使用 View 对象

使用 Views(index) 返回单个 View 对象,其中 indexView 对象的名称或序数。以下示例返回名为“Table View”的视图,并将其存储在名为“objView”的 View 类型的变量中。

Sub GetView()
'Creates a new view

    Dim olApp As Outlook.Application
    Dim objName As NameSpace
    Dim objViews As Views
    Dim objView As View

    Set olApp = Outlook.Application
    Set objName = olApp.GetNamespace("MAPI")
    Set objViews = objName.GetDefaultFolder(olFolderInbox).Views
    'Return a view called Table View
    Set objView = objViews.Item("Table View")

End Sub

使用 Views 集合的 Add 方法创建新的视图。以下示例新建一个名为“New Table”的 olTableView 类型的视图。

Sub CreateView()
'Creates a new view

    Dim olApp As Outlook.Application
    Dim objName As NameSpace
    Dim objViews As Views
    Dim objNewView As View

    Set olApp = Outlook.Application
    Set objName = olApp.GetNamespace("MAPI")
    Set objViews = objName.GetDefaultFolder(olFolderInbox).Views
    Set objNewView = objViews.Add(Name:="New Table", _
                     ViewType:=olTableView, SaveOption:=olViewSaveOptionThisFolderEveryone)

End Sub