Views.Add method (Outlook)

Creates a new view in the Views collection.

Syntax

expression.Add (Name, ViewType, SaveOption)

expression A variable that represents a Views object.

Parameters

Name Required/Optional Data type Description
Name Required String The name of the new view.
ViewType Required OlViewType The type of the new view.
SaveOption Optional OlViewSaveOption The save option that specifies the permissions of the new view:
  • olViewSaveOptionAllFoldersOfType The view can be accessed in all folders of this type.
  • olViewSaveOptionThisFolderEveryOne The view can be accessed by all users in this folder only.
  • olViewSaveOptionThisFolderOnlyMe The view can be accessed in this folder only by the user.

Return value

A View object that represents the new view.

Remarks

If you add a View to a Views collection of a folder that is not the current folder, you must first save a copy of the Views collection object and then add the View to this collection object, as shown in the following code sample. This is a work-around for an existing problem that will otherwise cause a call to View.Apply for the added View to fail.

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

Example

The following Visual Basic for Applications (VBA) example creates a new view called New Table and stores it in a variable called 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

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.