VBA 在 InputBox 后显示 MsgBox

时间:2021-03-18 08:41:13

标签: excel vba inputbox msgbox

输入框后不弹出消息框。

Dim Output As Integer
Dim name As Variant
Output = MsgBox("Are You Interested in taking a short survey with me?", vbYesNo + vbQuestion, "Short Survey")
If Output = vbYes Then
MsgBox "Great! I'll guide you through this"
name = InputBox("First Question, What's your name?")
If name = vbYes Then
MsgBox "Welcome"
Else
End If
Else
MsgBox "Thanks! But you can try again if you change your mind"
End If
End Sub

1 个答案:

答案 0 :(得分:0)

If name = vbYes Then 改为 If name <> "" Then

当您输入一些文本时,变量 name 获取该文本,而不是 vbYes

Dim Output As Integer
Dim name As Variant
Output = MsgBox("Are You Interested in taking a short survey with me?", vbYesNo + vbQuestion, "Short Survey")
If Output = vbYes Then
  MsgBox "Great! I'll guide you through this"
  name = InputBox("First Question, What's your name?")
  If name <> "" Then
    MsgBox "Welcome"
  End If
Else
  MsgBox "Thanks! But you can try again if you change your mind"
End If
相关问题