单击取消并退出按钮时保持循环

时间:2018-06-25 05:26:49

标签: vba

如果它为空,我正在尝试进行输入框循环,但是会遇到诸如单击“取消”和“退出”按钮也将显示相同结果并保持循环的问题。

Dim x As Variant



 Do
      x = InputBox("Please Input Yor  ID!")

       If x <> "" Then Exit Do
       MsgBox "ID cannot be Empty!"

Loop
     MsgBox ("id : " & x)

1 个答案:

答案 0 :(得分:0)

类似的东西:

Option Explicit

Public Sub LoopInputBox()
    Dim x As Variant
    Do
        DoEvents
        x = Application.InputBox("Please Input Yor  ID!")

        If TypeName(x) = "Boolean" Then Exit Sub

    Loop While x = vbNullString

    MsgBox ("id : " & x)
End Sub

这个想法来自here