macro message box

JasonLeVan

Board Regular
Joined
Feb 7, 2011
Messages
121
Is there a way to have a message box pop up but continue running the rest of my macro
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

capparfrank

New Member
Joined
Feb 11, 2011
Messages
41
Jason,

The important term you want to know is 'Modal.' A modal form or dialog is one that is going to cause it's parent to stop running until its own process is finished (sorry if you knew that already).

I am pretty confident that that VBA msgbox is always modal. There's no way to put one on the screen and have the macro that created it continue running.

However, Userforms can be non-modal. You can set up a userform to look a lot like a msgbox, if you want.

Code:
UserForm1.Show vbModeless

There may be better solutions, but this is how I'd do it. Remeber that you'll have to figure out when you want the userform to go away and either hide or unload it as necessary.
 
Upvote 0

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,894
Office Version
  1. 365
Platform
  1. Windows
Do you mean show a msgbox, dismiss it automatically and then continue with the rest of of the macro? If so, this will display a msgbox for 2 seconds, dismiss and then run the rest of the macro.

Code:
Public Sub test()
    Dim objWShell As Object, i
    Set objWShell = CreateObject("Wscript.Shell")
    
    objWShell.Popup "Boo!", 2
    
    'rest of macro
    
    MsgBox "done"
End Sub
 
Upvote 0

JasonLeVan

Board Regular
Joined
Feb 7, 2011
Messages
121
this will work great, how do i hide it when i am done with the display

Jason,

The important term you want to know is 'Modal.' A modal form or dialog is one that is going to cause it's parent to stop running until its own process is finished (sorry if you knew that already).

I am pretty confident that that VBA msgbox is always modal. There's no way to put one on the screen and have the macro that created it continue running.

However, Userforms can be non-modal. You can set up a userform to look a lot like a msgbox, if you want.

Code:
UserForm1.Show vbModeless

There may be better solutions, but this is how I'd do it. Remeber that you'll have to figure out when you want the userform to go away and either hide or unload it as necessary.
 
Upvote 0

capparfrank

New Member
Joined
Feb 11, 2011
Messages
41
Sorry for the long wait. Had a tough week over here :(


You can hide the userform and keep it around in memory. This is kind of nice if you find yourself wanting to build onto information that you've already put into the form once already. Just remember to unload it later on.

Code:
'from somewhere other than the userform
Userform1.Hide
 
'from the code launched from the form itself (like a button event)
Me.Hide

If you're done with it and you don't want invisible forms hogging up your resources, use unload.

Code:
'from somewhere other than the userform
Unload Userform1
 
'from the code launched from the form itself (like a button event)
Unload Me
 
Last edited:
Upvote 0

Forum statistics

Threads
1,191,696
Messages
5,988,149
Members
440,131
Latest member
EricMoz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top