Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Add Method
Collapse the table of content
Expand the table of content

Views.Add Method

Office 2007
Creates a new view in the Views collection.

Syntax

expression.Add(Name, ViewType, SaveOption)

expression   A variable that represents a Views object.

Parameters

NameRequired/OptionalData TypeDescription
NameRequiredStringThe name of the new view.
ViewTypeRequiredOlViewTypeThe type of the new view.
SaveOptionOptionalOlViewSaveOptionThe 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 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.

Visual Basic for Applications
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.

Visual Basic for Applications
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



Community Additions

ADD
Show:
© 2015 Microsoft