从MsgBox捕获输入

时间:2017-06-02 13:06:21

标签: excel vba excel-vba

我有一个问题,我无法理解。

我有一个userform,我有Yes告诉用户某些方框是否缺少信息,然后询问他们是否要继续。

当用户按下MsgBox时,userform的值将按原样传输到工作表中。但是当用户选择“否”时,仍会传输值...

当用户选择No时,如果没有转移值,如何关闭false

2 个答案:

答案 0 :(得分:0)

这是你想要的吗?

Sub Sample()
    Dim Ret As Variant

    Ret = MsgBox("Blah Blah", vbQuestion + vbYesNo)

    If Ret = vbYes Then
        MsgBox "You pressed `Yes`" '<~~ Code to transfer to the sheet here
    ElseIf Ret = vbNo Then
        MsgBox "You pressed `No`"
    End If
End Sub

答案 1 :(得分:0)

如果您只想在用户点击msgbox窗口中的“是”时将记录提交到工作表,您可以尝试这样的事情......

根据您的要求更换msgbox。

Dim Ans As Long
Ans = MsgBox("You didn't fill all the information." & vbNewLine & vbNewLine & "Do you want to continue?", vbQuestion + vbYesNo, "Confirm Please!")
If Ans = vbYes Then
    'Code to submit the records onto the Sheet
End If
相关问题