BeforeViewSwitch Event

Explorer.BeforeViewSwitch Event (Outlook)

Office 2013 and later
GitHub-Mark-64px

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Occurs before the explorer changes to a new view, either as a result of user action or through program code.

expression .BeforeViewSwitch(NewView, Cancel)

expression A variable that represents an Explorer object.

Parameters

Name

Required/Optional

Data Type

Description

NewView

Required

Variant

The name of the view the explorer is switching to.

Cancel

Required

Boolean

False when the event occurs. If the event procedure sets this argument to True, the switch is cancelled and the current view is not changed.

This event is not available in Microsoft Visual Basic Scripting Edition (VBScript).

This Microsoft Visual Basic for Applications (VBA) example confirms that the user wants to switch views and cancels the switch if the user answers No. The sample code must be placed in a class module, and the Initialize_handler routine must be called before the event procedure can be called by Microsoft Outlook.

Public WithEvents myOlExp As Outlook.Explorer 
 
 
 
Public Sub Initialize_handler() 
 
 Set myOlExp = Application.ActiveExplorer 
 
End Sub 
 
 
 
Private Sub myOlExp_BeforeViewSwitch(ByVal NewView As Variant, Cancel As Boolean) 
 
 Dim Prompt As String 
 
 
 
 Prompt = "Are you sure you want to switch to the " & NewView & " view?" 
 
 If MsgBox(Prompt, vbYesNo + vbQuestion) = vbNo Then Cancel = True 
 
End Sub
Show:
© 2016 Microsoft