在不暂停应用程序的情况下使用 MsgBox

发布于 2024-10-27 11:01:10 字数 110 浏览 5 评论 0原文

我需要向用户显示一条消息。当我使用 MsgBox 执行此操作时,程序将停止,直到用户单击该框为止。我想知道是否有办法在不暂停程序的情况下打开MsgBox

I need to display a message to the user. When I do this using MsgBox, the program stops until the user clicks the box away. I'd like to know if there's a way to open the MsgBox without pausing the program.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

悲欢浪云 2024-11-03 11:01:10

听起来您并不期望来自 MsgBox 的任何用户输入。在这种情况下,根据您的应用程序,StatusBar 可能是足够的替代品。

在 Excel 中,这很简单:

Application.StatusBar = "Please be patient..."
Application.StatusBar = iDone & " of " & iTotal & " items done."

完成后清除状态栏:

Application.StatusBar = False

在 Access 中,语法稍微复杂一些:

Temp = SysCmd(acSysCmdSetStatus, "Hey, look at me!") ' Puts out your message
Temp = SysCmd(acSysCmdClearStatus) ' Clears StatusBar

Sounds like you're not expecting any user input from the MsgBox. In this case, depending on your application, the StatusBar may be an adequate substitute.

In Excel this is easy:

Application.StatusBar = "Please be patient..."
Application.StatusBar = iDone & " of " & iTotal & " items done."

To clear the StatusBar when done:

Application.StatusBar = False

In Access, the syntax is a tiny bit more convoluted:

Temp = SysCmd(acSysCmdSetStatus, "Hey, look at me!") ' Puts out your message
Temp = SysCmd(acSysCmdClearStatus) ' Clears StatusBar
归途 2024-11-03 11:01:10

据我所知,答案是你不能。解决方法是使用一个充当对话框的自定义表单。

请参阅http://www.mvps.org/access/forms/frm0046.htm(不完全是您的问题,但适用)。

As far as I've ever been able to discover, the answer is you can't. The work-around is a custom form that serves as a dialog box.

See http://www.mvps.org/access/forms/frm0046.htm (not precisely your question, but applicable).

绾颜 2024-11-03 11:01:10

MsgBox 是模态的(意味着窗口出现并停止执行代码,直到它被清除)。正如其他发帖者/评论者所提到的 - 您的替代方案是编写您自己的非模式弹出窗口版本。除非你真的需要这样,否则并不值得付出努力。

MsgBox is modal (meaning the window comes up and halts execution of code until it is cleared). As other posters/commenters have mentioned - your alternative is to write your own version of a popup that is not modal. Not really worth the effort unless you really need it that way.

心房的律动 2024-11-03 11:01:10

在 VB 编辑器中:选择“插入”菜单“用户窗体”。
在工具箱中选择文本框:在用户窗体中拖动一个矩形并在其中键入文本。
右键单击用户窗体并选择属性。
在 ShowModal 属性中:选择 False。
在 VBA 模块中,在要打开它的位置输入 UserForm1.Show,在要关闭它的位置输入 UserForm1.Hide。
UserForm1 是我的,当然请使用您创建的表单的适当名称。

In the VB editor: Select Insert menu UserForm.
In the Toolbox select TextBox: Drag a rectangle in the UserForm and type your text into it.
Right click on the UserForm and select Properties.
In the ShowModal property: Select False.
In your VBA module enter UserForm1.Show where you want to turn it on and UserForm1.Hide where you want to turn it off.
UserForm1 is mine, of course use the appropriate name for the form you created.

夜灵血窟げ 2024-11-03 11:01:10

相反,创建一个表单。我创建了一个小表单,其中只有一个文本框,上面写着“正在工作,请稍候”。当需要时,我通常在开始某些需要一些时间才能完成的操作之前以弹出窗口形式打开表单(docmd openform“表单名称”)。工作完成后,我关闭表单(docmd close acform“表单名称”)。这不会停止程序,但会向用户提供“消息”。

Create a Form instead. I created a small form that only has a text box that says "Working, Please Wait". When needed I open the form, as a pop-up (docmd openform "form name"), usually just before starting some operation that is going to take some time to complete. When the work completes I close the form (docmd close acform "form name"). This does not stop the program but does provide a "Message" to the user.

雨后彩虹 2024-11-03 11:01:10

您可以使用 WScript 的 Popup 方法。以下是包括示例代码的完整详细信息: http:// /msdn.microsoft.com/en-us/library/x83z1d9f%28v=vs.85%29.aspx

You can use WScript's Popup method. Here's the full details including sample code: http://msdn.microsoft.com/en-us/library/x83z1d9f%28v=vs.85%29.aspx

我做我的改变 2024-11-03 11:01:10

我相信您首先需要评估是否真的需要弹出消息框并保持代码运行。

msgbox 功能(如前所述)是模态的,您无法“绕过”它。但是,您可以创建一个表单(类似于 msgbox),将此表单设置为“非模态”并调用代码来显示此表单。代码工作流程继续进行。经过测试并可在 Excel 中使用。

I believe you first need to evaluate if you really need a msgbox to pops-up and keep your code running.

The msgbox functionality (as already stated) is modal and you cannot 'bypass' it. However, you can create a form (similar to the msgbox), set this form as 'not Modal' and call the code to show this form. The code workflow goes on. Tested and works in Excel.

凉城已无爱 2024-11-03 11:01:10

你可以用这个。它为我创建了一个 Outlook 对话框:

Dim myMessage as String  
Dim myDelay as Integer  
myMessage = "This message will self destruct in 8 seconds!"  
myDelay = 8  
Shell "msg /TIME:" & myDelay & " " & Environ("Username") & " " & myMessage  

You can use this. It worked for me to create a dialog for outlook:

Dim myMessage as String  
Dim myDelay as Integer  
myMessage = "This message will self destruct in 8 seconds!"  
myDelay = 8  
Shell "msg /TIME:" & myDelay & " " & Environ("Username") & " " & myMessage  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文