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 Ms开发者_运维技巧gBox
without pausing the program.
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
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).
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.
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.
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.
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
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.
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
精彩评论