Explorer.BeforeMove Event (Outlook)


Contribute to this content

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

Occurs when the Explorer is moved by the user.

expression .BeforeMove(Cancel)

expression A variable that represents an Explorer object.




Data Type





False when the event occurs. If the event procedure sets this argument to True, the operation is not completed and the explorer or inspector is not moved.

This event can be cancelled after it has started.

The following Microsoft Visual Basic for Applications (VBA) example prompts the user with a message before the explorer is moved by the user. If the user clicks Yes, the explorer can be moved by the user. The sample code must be placed in a class module such as ThisOutlookSession, and the Initialize_Handler() subroutine should be called before the event procedure can be called by Microsoft Outlook.

Public WithEvents myOlExp As Outlook.Explorer 
Sub Initalize_Handler() 
 Set myOlExp = Application.ActiveExplorer 
End Sub 
Private Sub myOlExp_BeforeMove(Cancel As Boolean) 
'Prompts the user before moving the window 
 Dim lngAns As Long 
 lngAns = MsgBox("Are you sure you want to move the current window? Use your keyboard to make your selection.", vbYesNo) 
 If lngAns = vbYes Then 
 Cancel = False 
 Cancel = True 
 End If 
End Sub
© 2015 Microsoft