Views.Add (Outlook)

Creates a new view in the Views collection.

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.

Add (Name, ViewType, SaveOption)


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

Arguments

The following arguments are required:

Name (String) - The name of the new view.

ViewType (OlViewType) - The type of the new view.

Here you can find possible values for OlViewType

Optional arguments

The following argument is optional

SaveOption (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.

Possible return values are olViewSaveOptionAllFoldersOfType - Indicates that the view is available in all folders of the same type, olViewSaveOptionThisFolderEveryone - Indicates that the view is only available in the current folder and is available to all users, olViewSaveOptionThisFolderOnlyMe - Indicates that the view is only available in the current folder and is only available to the current Outlook user.