首页 > 解决方案 > 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

标签: excelvbainputboxmsgbox

解决方案


更改If name = vbYes ThenIf 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

推荐阅读