如何检查是否closuresExcel(工作簿)VBA

我正在寻找一个代码,可以返回一个boolean 0truefalse ,以便它可以识别是否有人通过点击XclosuresExcel

打开VBA编辑器,然后继续ThisWorkbook (在IDE左侧的项目树中),您将访问工作簿事件的代码。

然后,从右上angular的下拉列表中select左上angular下拉菜单中的Workbook对象之后的事件BeforeClose ,并在模块上获得以下代码:

 Private Sub Workbook_BeforeClose(Cancel As Boolean) End Sub 

每次有人试图closures工作簿时都会调用该macros。 在那里,你可以放一个全局variables来控制这个动作,像这样:

 someoneIsClosing = True '<-- this is a globally defined variable Cancel = True '<-- if you want to cancel the closing action myMacro '<-- if you want to go back to "myMacro", ie any macro of your project and delegate it from handling the event.