Edit

Share via


_Views.Add(String, OlViewType, OlViewSaveOption) Method

Definition

Creates a new view in the Views collection.

public Microsoft.Office.Interop.Outlook.View Add (string Name, Microsoft.Office.Interop.Outlook.OlViewType ViewType, Microsoft.Office.Interop.Outlook.OlViewSaveOption SaveOption);
Public Function Add (Name As String, ViewType As OlViewType, Optional SaveOption As OlViewSaveOption) As View

Parameters

Name
String

The name of the new view.

ViewType
OlViewType

The type of the new view.

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.

Returns

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 code sample below. This is a work-around for an existing problem which will otherwise cause a call to Apply() for the added View to fail.

Sub CalendarView()
    Dim calView As Outlook.View
    Dim vws As Outlook.Views

    Application.ActiveExplorer.CurrentFolder = _
        Application.Session.GetDefaultFolder( _
        Outlook.OlDefaultFolders.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
    vws = Application.Session.GetDefaultFolder( _
        Outlook.OlDefaultFolders.olFolderCalendar).Views

    ' Add the View to this Views collection object
    calView = vws.Add("New Calendar", _
        Outlook.OlViewType.olCalendarView, _
        Outlook.OlViewSaveOption.olViewSaveOptionThisFolderEveryone)
    calView.Save()
    ' This Apply call will be fine.
    calView.Apply()
End Sub
private void CalendarView()
{
    Outlook.View calView;
    Outlook.Views vws;

    Application.ActiveExplorer().CurrentFolder = 
        Application.Session.GetDefaultFolder( 
        Outlook.OlDefaultFolders.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
    vws = Application.Session.GetDefaultFolder( 
        Outlook.OlDefaultFolders.olFolderCalendar).Views;

    //Add the View to this Views collection object
    calView = vws.Add("New Calendar",
        Outlook.OlViewType.olCalendarView, 
        Outlook.OlViewSaveOption.olViewSaveOptionThisFolderEveryone);
    calView.Save();
    // This Apply call will be fine.
    calView.Apply();
}

Applies to