按下命令按钮后,我希望弹出一个窗口,询问“这些更改无法撤消。建议在继续之前保存副本。您想继续吗?”
我想要三个选择:
- 是 - 弹出窗口关闭并执行 CommandButton 宏
- 否 - 这将关闭弹出窗口并且不会更改任何内容
- 保存 - 关闭弹出窗口并打开“另存为”(不执行宏)
我真的不知道从哪里开始。你能帮我一下吗?
真的非常感谢。
最佳答案
您可以使用消息框,但这有些限制。您可以稍微改写问题以使用 vbYesNoCancel
按钮,因为另存为
不是消息框上的可选按钮。
然后您可以使用消息框按钮单击的结果:
Dim mbResult as Integer
mbResult = MsgBox("These changes cannot be undone. Would you like to save a copy before proceeding?", _
vbYesNoCancel)
Select Case mbResult
Case vbYes
'Modify as needed, this is a simple example with no error handling:
With ActiveWorkbook
If Not .Saved Then .SaveAs Application.GetSaveAsFilename()
End With
Case vbNo
' Do nothing and allow the macro to run
Case vbCancel
' Do NOT allow the macro to run
Exit Sub
End Select
关于vba - Excel VBA : Confirmation on Pressing CommandButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16839149/