Views.ViewAdd event (Outlook)

Occurs when a view is added to the collection. Microsoft Outlook creates the new view and passes it to this event.

Syntax

expression. ViewAdd( _View_ )

expression A variable that represents a Views object.

Parameters

Name Required/Optional Data type Description
View Required View The new view added to the collection prior to this event.

Example

The following Microsoft Visual Basic for Applications (VBA) example displays the view's name and saves it when the ViewAdd event is fired. Use the Save method after the properties have been modified to save the changes to the view. The sample code must be placed in a class module such as ThisOutlookSession, and the AddView() procedure should be called before the event procedure can be called by Outlook.

Public WithEvents objViews As Outlook.Views 
 
 
 
Sub AddView() 
 
 Dim objView As Outlook.View 
 
 Set objViews = Application.ActiveExplorer.CurrentFolder.Views 
 
 Set objView = objViews.Add("Latest View1", olTableView, olViewSaveOptionAllFoldersOfType) 
 
End Sub 
 
 
 
Sub objViews_ViewAdd(ByVal View As View) 
 
'Displays name of new view 
 
 With View 
 
 Msgbox .Name & " was created programmatically." 
 
 .Save 
 
 End With 
 
End Sub

See also

Views Object

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.