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.
expression A variable that represents a Views object.
|View||Required||View||The new view added to the collection prior to this event.|
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