ViewAdd Event
Occurs when a view is added to the collection. Microsoft Outlook creates the new view and passes it to this event.
Subexpression_ViewAdd(ByVal View As View)
*expression * A variable which references an object of type **Views**declared with events in a class module.
*View * The new view added to the collection prior to this event.
Example
The following Microsoft Visual Basic/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 Microsoft Outlook.
Public WithEvents objViews As Outlook.Views
Sub AddView()
Dim myOlApp As New Outlook.Application
Dim objView As Outlook.View
Set objViews = myOlApp.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
Applies to | Views Collection
See Also | View Object | Views Collection | ViewSwitch Event