title | keywords | f1_keywords | api_name | ms.assetid | ms.date | ms.localizationpriority | ||
---|---|---|---|---|---|---|---|---|
Views.Add method (Outlook) |
vbaol11.chm547 |
|
|
8005ca2e-8b28-1286-74d1-448f2a168c65 |
02/16/2019 |
medium |
Creates a new view in the Views collection.
expression.Add (Name, ViewType, SaveOption)
expression A variable that represents a Views object.
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:
|
A View object that represents the new view.
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
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
[!includeSupport and feedback]