The DefineExitEvent macro creates an exit event using the OnEvent method. This event calls the ExitCheck macro shown next. You could define an equivalent event using the Event Setup dialog box. (Line continuation characters—an underscore preceded by a space—are used in these examples to break up long lines.)

Sub DefineExitEvent()

 Session.OnEvent rcNextEvent, rcReflectionExit, rcVBMacro, _

     "ExitCheck", rcEnable, rcEventReenable

End Sub

ExitMacro gives the user an opportunity to cancel the exit event using the CancelExitEvent method. Note: If you have not saved your settings, you will see Reflection's SaveChangesOnExit dialog box before you see the message box created by this exit macro.

Sub ExitCheck

'Cancel an exit event if the user says to


 Dim result As Integer


 result = MsgBox("Reflection will now exit. Is this OK?", vbYesNo, _

     "Custom Exit Prompt")


 'Cancel the exit event only if the user selected No

 Select Case result

  Case vbYes

   Exit Sub

  Case vbNo


 End Select

End Sub