我从 Microsoft 网站获得了此代码。
无论我选择“是”还是“否”,文件都会保存。
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel as Boolean)
a = MsgBox("Do you really want to save the workbook?", vbYesNo)
If a = vbNo Then Cancel = True
End Sub
如果你测试会发生什么
IF MsgBox("Do you really want to save the workbook?", vbYesNo) = vbNo then Cancel=True