_Views.Add Method

Creates a new view in the Views collection.

Namespace:  Microsoft.Office.Interop.Outlook
Assembly:  Microsoft.Office.Interop.Outlook (in Microsoft.Office.Interop.Outlook.dll)

Syntax

'Declaration
<DispIdAttribute()> _
Function Add ( _
    Name As String, _
    ViewType As OlViewType, _
    SaveOption As OlViewSaveOption _
) As View
'Usage
Dim instance As _Views
Dim Name As String
Dim ViewType As OlViewType
Dim SaveOption As OlViewSaveOption
Dim returnValue As View

returnValue = instance.Add(Name, ViewType, _
    SaveOption)
[DispIdAttribute()]
View Add(
    string Name,
    OlViewType ViewType,
    OlViewSaveOption SaveOption
)

Parameters

  • SaveOption
    Type: Microsoft.Office.Interop.Outlook.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

Type: Microsoft.Office.Interop.Outlook.View
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 View.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();
}

See Also

Reference

_Views Interface

_Views Members

Microsoft.Office.Interop.Outlook Namespace

Other Resources

How to: Create a View