大家好,最近在自学VBA,想请问Application.Quit无法执行的原因?
1.原本只有如下,能够正常执行退出Excel
Private Sub Workbook_Open()
Dim checkterm As Variant
Dim boxmentionSentence As String
boxmentionSentence = "Welcome to Template V2.0 !" & vbNewLine &
vbNewLine & "Are you ready to enjoy it ?" _
& vbNewLine & "(If NO, close workbook and quit Excel)"
checkterm = MsgBox(boxmentionSentence, vbYesNo + vbInformation, boxTitle)
If checkterm = vbYes Then
End If
If checkterm = vbNo Then
Application.DisplayAlerts = False
ThisWorkbook.Saved = True
Application.Quit
End If
End Sub
2.接着为了达到“停用宏则关闭活页簿”,google找了如下的方法
i. 新增 Excel 4.0 宏表 Macro1,输入以下
停用宏则关闭活页簿
=ERROR(FALSE) ←这个Cell为Macro1!$A$2
=IF(ERROR.TYPE(RUN("TestMacro"))=4)
= ALERT("因停用了宏功能,档案将被关闭!",3)
= FILE.CLOSE(FALSE)
=END.IF()
=RETURN
ii.在工作表“插入”→“名称”→“定义”Auto_Activate,指向 Macro1!$A$2
开启档案后,选择“停用宏”,确实弹出Msgbox并且能够关闭活页簿。