MsgBox是/否Excel VBA

编程入门 行业动态 更新时间:2024-10-06 01:34:38
本文介绍了MsgBox是/否Excel VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的VBA脚本中有一个 Yes/No MsgBox ,它返回一个问题供用户回答.每当按下是"或否"按钮时,除了脚本运行其各自的代码外,还会弹出另一个带有数字"6"或"7"的 MsgBox .如何禁用第二个 MsgBox ?

I have a Yes/No MsgBoxin my VBA script that returns a question for the user to answer. Whenever the "Yes" or "No" buttons are pressed, besides the script running its respective code, another MsgBox with the numbers "6" or "7" pops up. How do I disable this second MsgBox?

这是我的代码:

Dim question As Integer question = MsgBox("Unfortunately, the Database has no sources regarding " & Category & " in " & country & ". Would you like to broaden your search and see all sources regarding " & country & "?", vbYesNo + vbQuestion, "Empty Sheet") MsgBox question If question = vbYes Then Sheets("Results").Range("D6").ClearContents Sheets("Results").Range("D7").ClearContents Category = Sheets("Results").Range("D6").Value Else Sheets("Results").Range("D5").ClearContents Sheets("Results").Range("D6").ClearContents Sheets("Results").Range("D7").ClearContents Exit Sub End If

推荐答案

MsgBox 函数返回一个 vbMsgBoxResult 值,该值是一个枚举(应为 Long 整数,而不是 Integer ).

The MsgBox function returns a vbMsgBoxResult value, which is an enum (and should be a Long integer, not an Integer).

您打过两次电话:

Dim question As Integer question = MsgBox("Unfortunately, the Database has no sources regarding " & Category & " in " & country & ". Would you like to broaden your search and see all sources regarding " & country & "?", vbYesNo + vbQuestion, "Empty Sheet") MsgBox question

一次分配 question ,并一次显示 question -此时将包含 vbYes (6)或 vbNo (7).

Once to assign question, and once to display question - which at that point is going to contain either vbYes (6) or vbNo (7).

我会将 question声明为vbMsgBoxResult ,以避免歧义并在以后使用它时获得autocomplete/IntelliSense.实际上, result 或 answer 会是更好的标识符-"question"听起来像问题本身,而不是用户的响应.

I would declare question As vbMsgBoxResult to avoid ambiguities and get autocomplete/IntelliSense when you later use it. Actually, result or answer would be a better identifier - "question" sounds like the question itself, not the user's response.

更多推荐

MsgBox是/否Excel VBA

本文发布于:2023-11-28 03:15:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640749.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:MsgBox   Excel   VBA

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!