我有一个简单的脚本,在关闭工作簿之前需要密码(以防止意外关闭),但是如果输入正确的关键字,InputBox将重新打开。我已经创建了以下脚本的多个迭代,但我无法解决它。
Sub Workbook_BeforeClose(Cancel As Boolean)
If InputBox("Please enter the password to close the workbook.") <> "pa55word" Then
MsgBox ("Incorrect password. Please try again")
Cancel = True
Exit Sub
Else
GoTo GoToClose
End If
GoToClose:
ThisWorkbook.Close SaveChanges:=False
End Sub发布于 2015-09-03 01:23:21
如果你像这样编码:
ThisWorkbook.Saved告诉Excel工作簿已经完全更新,所以不会有您想保存消息的情况--也就是说,它执行与ThisWorkbook.Close SaveChanges:=False的False部分相同的任务,而现有的保存事件关闭了工作簿。重合件
Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Saved = True
If InputBox("Please enter the password to close the workbook.") <> "pa55word" Then
MsgBox ("Incorrect password. Please try again")
Cancel = True
End If
End Sub发布于 2015-09-02 20:47:25
关闭之前禁用事件。
https://stackoverflow.com/questions/32362754
复制相似问题