Friday, January 11, 2019

Temporary and or Non-modal Messagebox in VBA Excel

Sometimes you want to display a non-modal temporary messagebox in VBA. Many people will tell you that this is not possible, or they give you unreliable code to use Wscript.popup.

However, there is another solution!!

Enter in the simple one-line solution for Windows 7, 8 and 10. I think it is applicable to all versions, but it may only be the Professional versions. You will have to test that on your own.

Here it is!


 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  

Just place this code wherever you want to send a temporary message.  You can change myDelay to the delay (in seconds) that you want (or remove "/TIME:" & myDelay & " "" altogether). You also just modify myMessage to be the message you would like! (Don't forget to use escape characters for quotation marks)

This will create a nice and simple messagebox with your message. The messagebox will disappear after your specified delay time. It will also not inhibit the VBA code from continuing. That means, you can show a message to the user while processing other things!

You're Welcome!

No comments:

Post a Comment

VBA Add an animated Notification Box to your Excel Program

For those of us who create programs and add-ins in Excel, we are very, very familiar with the message box.  The message box gives us the opp...