如何重新设置excel的关闭[x]按钮

时间:2016-04-01 15:32:52

标签: excel excel-vba vba

我有这个代码禁用excel的close [x]功能。完成输入ID后,我需要再次启用按钮。

我有这个部分禁用[x],

Public FlagToClose As Boolean
Sub Enter_1()
    FlagToClose = False

    'code
    '.....................

    FlagToClose = True
End Sub

对于workbook模块,我有这个,

Private Sub Workbook_Open()
    FlagToClose = True
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    If Not FlagToClose Then Cancel = True
End Sub

那么如何再次启用关闭[x]函数?

1 个答案:

答案 0 :(得分:0)

要重新启用关闭,请在关闭之前运行此短宏:

Sub ev_off()
    Application.EnableEvents = False
End Sub