title: Excel 2019 - How To Detect The Selection Made On Excel Main Menu "File" Dropdown Using VBA?
body: <p>How do I detect the selection made in the File dropdown of the Excel 2019 main menu using VBA?  I am specifically trying to capture the Close selection in the File dropdown.  Is this possible?</p>
  <p>The specific problem I'm having is that I want to display the Trust Center's MacroSecurity window (<code>Application.CommandBars.ExecuteMso (&quot;MacroSecurity&quot;)</code>) to the user using the ThisWorkbook module's Workbook_BeforeClose event and it errors when the user clicks the red &quot;X&quot; that closes Excel (I'm <em>assuming</em> because the Excel CommandBars environment has been closed).  Using Excel's main menu &quot;File&quot; option and selecting &quot;Close&quot; closes only the workbook, so the MacroSecurity window displays correctly before closing the workbook.  If I had a main menu File selection event that I could write code to I would be able to limit closing the workbook AND displaying the MacroSecurity window to only the selection of the &quot;Close&quot; option in the &quot;File&quot; main menu.</p>
  <p>From my research it appears the the red &quot;X&quot; and the File&gt;Close options are both tied to the ThisWorkbook module's Workbook_BeforeClose event.  If that's correct, is there any way to determine which method triggered the Workbook_BeforeClose event - the red &quot;X&quot; or the File&gt;Close selection (or the keyboard, etc.)?</p>