message box without the "OK" button

fry

Active Member
Joined
Apr 25, 2007
Messages
411
Hi All

I'm using the following code to try and get a popup window to give the user a warning that the workbook is about to shut down but I'm getting an "OK" button to be pressed.

Is there a setting that will just popup a window rather than you having to press a button...............and can the window size be specified???

Thanks for any help in advance :)

Code:
Application.OnTime Now + TimeValue("00:00:20"), "close_workbook"
MsgBox "This Order Book will self destruct in 15 seconds...", vbExclamation, "User Notice"

Sub close_workbook()
Application.Quit
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
try

Code:
Application.OnTime Now + TimeValue("00:00:20"), "close_workbook"
CreateObject("WScript.Shell").popup "This Order Book will self destruct in 15 _
         seconds...", 18, "User Notice", vbOKOnly+vbExclamation

Sub close_workbook()
Application.Quit
End Sub
 
Upvote 0

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
I don't think that solves the problem of having to click on the OK button as the popup is modal? It seemed to be waiting for me to click OK before it did anything.

Another option would be to create a userform for the purpose which you could obviously resize and have no buttons on it.
 
Upvote 0

fry

Active Member
Joined
Apr 25, 2007
Messages
411
Thanks for your replies guys and sorry to say this but I've never used a userform before :( how would I do that???

Would I therefore be correct in thinking that there isn't a way of "not having" a button on the messagebox?
 
Upvote 0

jindon

MrExcel MVP
Joined
Aug 21, 2004
Messages
16,995
Do you really want to wait 20 sec anyway?
Otherwise
Code:
Dim x
x = CreateObject("WScript.Shell").popup "This Order Book will self destruct in 15 _
         seconds...", 18, "User Notice", vbOKOnly+vbExclamation
If x = 1 Or x = -1 Then close_workbook

Sub close_workbook()
Application.Quit
End Sub
 
Upvote 0

fry

Active Member
Joined
Apr 25, 2007
Messages
411
Hi jindon

I tried the above but got the following...

"Compile error: Syntax error" with the following code highlighted
Code:
x = CreateObject("WScript.Shell").popup "This Order Book will self destruct in 15 _
         seconds...", 18, "User Notice", vbOKOnly+vbExclamation

:(
 
Upvote 0

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Just navigate to your workbook in the VBE and right-click and go Insert>Userform. This will create your userform - drag a label onto it from the Controls Toolbox which should appear alongside the Userform and write your message in it (eg "This workbook will close in 15 seconds" or whatever).

Then use code very similar to what you already have to call the userform (in a modeless state):

Code:
Sub test()
Application.OnTime Now + TimeValue("00:00:15"), "closeths"
UserForm1.Show vbModeless
End Sub
Sub CloseThs()
ThisWorkbook.Close
End Sub
 
Upvote 0

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Just some missing parentheses re Jindon's code:

Code:
x = CreateObject("WScript.Shell").popup("This Order Book will self destruct in 15" & _
         "seconds...", 18, "User Notice", vbOKOnly + vbExclamation)

Still don't think that does exactly what you want though - but the userform route does.
 
Upvote 0

fry

Active Member
Joined
Apr 25, 2007
Messages
411
Thanks Richard and Jindon it actually does work. Even though there is an "OK" button it shuts down!!

My sincere thanks...:)
 
Upvote 0

Forum statistics

Threads
1,191,125
Messages
5,984,786
Members
439,911
Latest member
dk73

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