带有多个选项的MS Excel / VB消息框

时间:2017-06-22 08:47:35

标签: excel vba excel-vba

我正在尝试使用3个按钮在Excel中创建一个消息框

我可以创建3个按钮并显示相关信息但是我无法让每个按钮执行不同的操作

请参阅下面我已经开始的编码,但我知道它不正确

不要太在意这些行动,因为我更关心的是如何让每个按钮做一个单独的动作

非常感谢 蚂蚁

Sub Macro1()
'Macro1
If MsgBox( _
Prompt:="Are you sure you want to clear the events from the previous log?    Click YES to confirm or NO to keep events or cancel.", _
Buttons:=vbYesNoCancel) Then If vbYes Then Range("A1") = Range("A1") + 1 'increment hidden sequence num

nosoumission = noclient & Range("A1")
Sheets("Sheet1").Range("G9") = nosoumission
Range("B13").ClearContents
Application.Dialogs(xlDialogSaveAs).Show

If vbNo Then Range("A1") = Range("A1") + 1 'increment hidden sequence num

nosoumission = noclient & Range("A1")
Sheets("Sheet1").Range("G9") = nosoumission
Application.Dialogs(xlDialogSaveAs).Show

If vbCancel Then Exit Sub

End Sub

1 个答案:

答案 0 :(得分:0)

我怀疑你正在尝试这样做:

Sub Macro1()
    Select Case MsgBox(Prompt:="Are you sure you want to clear the events from the previous log?    Click YES to confirm or NO to keep events or cancel.", _
                       Buttons:=vbYesNoCancel)
        Case vbYes
            Range("A1") = Range("A1") + 1 'increment hidden sequence num
            nosoumission = noclient & Range("A1")
            Sheets("Sheet1").Range("G9") = nosoumission
            Range("B13").ClearContents
            Application.Dialogs(xlDialogSaveAs).Show
        Case vbNo
            Range("A1") = Range("A1") + 1 'increment hidden sequence num
            nosoumission = noclient & Range("A1")
            Sheets("Sheet1").Range("G9") = nosoumission
            Application.Dialogs(xlDialogSaveAs).Show
        Case vbCancel
            Exit Sub
    End Select
End Sub