Excel VBA: Confirmation on Pressing CommandButton

后端 未结 2 976
自闭症患者
自闭症患者 2021-01-12 06:33

Upon pressing my CommandButton, I would like to have a pop-up that asks \"These changes cannot be undone. It is advised to save a copy before proceeding. Do you wish to proc

2条回答
  •  鱼传尺愫
    2021-01-12 06:58

    I suggest you put code at the top of your macro to ask this question and respond to the answer.

    This would look something like:

    Sub YourMacro()
    
      if MsgBox("These changes cannot be undone. It is advised to save a copy before proceeding. Do you wish to proceed?", vbYesNo + vbQuestion) = vbNo then
        exit sub
      end if
    
      ... the rest of your macro.
    

    Note that this will not give the user the Save option. You can't do that with a standard MsgBox. If you want to do that, you will need to create your own userform, show that instead of the MsgBox and respond to what button in the Userform the user pushed. That is a lot more work for you than just using a MsgBox, but if you want your UI to be fancy, it may be worth it.

提交回复
热议问题