vba - Excel VBA : Confirmation on Pressing CommandButton

标签 vba excel

按下命令按钮后,我希望弹出一个窗口,询问“这些更改无法撤消。建议在继续之前保存副本。您想继续吗?”

我想要三个选择:

  1. 是 - 弹出窗口关闭并执行 CommandButton 宏
  2. 否 - 这将关闭弹出窗口并且不会更改任何内容
  3. 保存 - 关闭弹出窗口并打开“另存为”(不执行宏)

我真的不知道从哪里开始。你能帮我一下吗?

真的非常感谢。

最佳答案

您可以使用消息框,但这有些限制。您可以稍微改写问题以使用 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/

相关文章:

excel - instr 函数中的逗号是什么意思?

vba - 自动筛选后应用高级筛选

C# Excel 如何使用单元格链接添加超链接

excel - 我需要复制多张纸中的特定范围并将它们粘贴到最后一张纸上

excel - 如何使用 Excel VBA 单击网页上的链接?

excel - 在 Excel 中,需要计算从条件格式中着色的单元格,然后创建特定结果的报告

excel - 删除 Excel 单元格中的换行符、回车符和所有前导空格

arrays - 如何将选定范围复制到给定数组中?

java - 来自 Apache POI 的文件 Excel 无法由 Ms Excel 打开(损坏)

excel - 运行时错误 1004 Excel 2013