Views object (Outlook)

Contains a collection of all View objects in the current folder.

Remarks

Use the Views property of the Folder object to return the Views collection. Use Views (index),where index is the object's name or position within the collection, to return a single View object.

Use the Add method of the views collection to add a new view to the collection.

Use the Remove method to remove a view from the collection.

Example

The following example returns a View object of type olTableView called Table View. Before running this example, make sure a view by the name 'Table View' exists.

Sub GetView() 
 
 'Returns a view called Table View 
 
 Dim objName As NameSpace 
 
 Dim objViews As Views 
 
 Dim objView As View 
 
 
 
 Set objName = Application.GetNamespace("MAPI") 
 
 Set objViews = objName.GetDefaultFolder(olFolderInbox).Views 
 
 'Return a view called Table View 
 
 Set objView = objViews.Item("Table View") 
 
End Sub

The following example adds a new view of type olIconView in the user's Notes folder.

Note

The Add method will fail if a view with the same name already exists.

Sub CreateView() 
 
 'Creates a new view 
 
 Dim objName As NameSpace 
 
 Dim objViews As Views 
 
 Dim objNewView As View 
 
 
 
 Set objName = Application.GetNamespace("MAPI") 
 
 Set objViews = objName.GetDefaultFolder(olFolderNotes).Views 
 
 Set objNewView = objViews.Add(Name:="New Icon View Type", _ 
 
 ViewType:=olIconView, SaveOption:=olViewSaveOptionThisFolderEveryone) 
 
 
 
End Sub

The following example removes the above view, "New Icon View Type", from the collection.

Sub DeleteView() 
 
 'Deletes a view from the collection 
 
 Dim objName As NameSpace 
 
 Dim objViews As Views 
 
 Dim objNewView As View 
 
 
 
 Set objName = Application.GetNamespace("MAPI") 
 
 Set objViews = objName.GetDefaultFolder(olFolderNotes).Views 
 
 objViews.Remove ("New Icon View Type") 
 
End Sub

Events

Name
ViewAdd
ViewRemove

Methods

Name
Add
Item
Remove

Properties

Name
Application
Class
Count
Parent
Session

See also

Outlook Object Model Reference

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.