微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

VBA 在 InputBox 后显示 MsgBox

如何解决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

解决方法

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。