MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Feb 27th, 2002, 04:15 PM   #1
brettvba
MrExcel MVP
 
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
Default

I want to open a workbook display a msgbox to ask if you want to run the macro then say after ten seconds it automatically runs the macro can this be done?
brettvba is offline   Reply With Quote
Old Feb 27th, 2002, 04:40 PM   #2
gplhl
Board Regular
 
Join Date: Feb 2002
Location: Chippenham, UK
Posts: 136
Default

Quote:
On 2002-02-27 15:15, brettvba wrote:
I want to open a workbook display a msgbox to ask if you want to run the macro then say after ten seconds it automatically runs the macro can this be done?
Lookup Timer in the VBA online help.



__________________
Regards,

Gary Hewitt-Long
gplhl is offline   Reply With Quote
Old Feb 27th, 2002, 04:48 PM   #3
Damon Ostrander
MrExcel MVP
 
Damon Ostrander's Avatar
 
Join Date: Feb 2002
Location: Denver, Colorado USA
Posts: 4,014
Default

Hi BrettVBA,

I don't believe you can do this in versions of Excel earlier than 2000 because I believe the userform must be non-modal.

All you have to do is, in the userform's initialize event, use the Application object's OnTime method to schedule your macro to run 10 seconds in the future (you can look this up in the VBA helps). I believe the syntax looks like this:

Application.OnTime Now() + 10/86400, "MyMacro"

but I can't check this because I'm on a computer without VBA helps right now.

If before the 10 seconds is up, the user runs it or cancels it, the OnTime method also provides a means to cancel the future scheduled macro.

You can also put the

Unload UserForm1

operation in the macro so that it automatically gets rid of the userform. Also, as I mentioned, you must set the userform's ShowModal property to FALSE.
__________________
Keep Excelling.

Damon

VBAexpert Excel Consulting
(My other life: http://damonostrander.com )
Damon Ostrander is offline   Reply With Quote
Old Feb 27th, 2002, 04:59 PM   #4
brettvba
MrExcel MVP
 
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
Default

What I ment was I have a msgbox under workbook open event and its just a msgbox no form can a macro be run without the user pressing yes or no or cancel after 10 seconds


just to speak out loud
brettvba is offline   Reply With Quote
Old Feb 27th, 2002, 05:05 PM   #5
Guest
 
Posts: n/a
Default

Hi again Brett,

Sorry. You said MessageBox, but I was thinking TextBox.

No, I don't believe you can do this because the MsgBox function produces a dialog that is modal. You cannot do anything, and I don't believe even OnTime scheduled macros can run, until you respond to the MsgBox. You really have to create a custom userform that functions like a messagebox (very easy).
  Reply With Quote
Old Feb 28th, 2002, 02:13 AM   #6
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Quote:
On 2002-02-27 16:05, Anonymous wrote:
Hi again Brett,

Sorry. You said MessageBox, but I was thinking TextBox.

No, I don't believe you can do this because the MsgBox function produces a dialog that is modal. You cannot do anything, and I don't believe even OnTime scheduled macros can run, until you respond to the MsgBox. You really have to create a custom userform that functions like a messagebox (very easy).
Yes you can do this in excel2000 using the
Address of Functon and a bit of API trickery
to get a timed mesgbox.

I have made a Class module to do this if
interested....probably don't need the class
but it was a good exercise as I have noticed
the call for a Timed msgbox ie one that dismisses itself at a set time.


Ivan
Ivan F Moala is offline   Reply With Quote
Old Feb 28th, 2002, 12:12 PM   #7
brettvba
MrExcel MVP
 
Join Date: Feb 2002
Location: Christchurch New Zealand
Posts: 1,030
Default

Yeah that would be great Ivan im running office xp so hopefully that will run cheers.
brettvba is offline   Reply With Quote
Old Mar 1st, 2002, 02:29 AM   #8
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Hi Bret

The Code below will give you a timed msgbox
Just use it like a normal msgbox with the typical options....only Diff is that you set the time it displays for.
Have a play with it....

Ivan

'---------------------------------------------------------------------------------------
' Module : CodeTimer
' DateTime : 12/01/02 14:33
' Author : Ivan F Moala
' Note:
' Office 97 does not support the "AddressOf" operator which is needed to tell Windows
' where our "call back" function is.
'
' Inputs :
' Outputs :
'---------------------------------------------------------------------------------------
Option Explicit
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerfunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long

'==========Public Declarations ==============================
Public TimerID As Long 'Turn on and off with this ID
Public TimerActive As Boolean 'Is the timer active
Public Const tmMin As Long = 2 'Min time allowed
Public Const tmDef As Long = 5 'Default if min set low
'============================================================

Public Sub ActivateMyTimer(ByVal Sec As Long)
Sec = Sec * 1000
If TimerActive Then Call DeActivateMyTimer

On Error Resume Next
TimerID = SetTimer(0, 0, Sec, AddressOf Timer_CallBackFunction)
TimerActive = True

End Sub

Public Sub DeActivateMyTimer()
KillTimer 0, TimerID
End Sub

Sub Timer_CallBackFunction(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idevent As Long, _
ByVal Systime As Long)
Application.SendKeys "~", True

If TimerActive Then Call DeActivateMyTimer
End Sub

Function TmMsgBox(sMsg As String, Btn As VbMsgBoxStyle, Optional ShowFor As Long, _
Optional sTitle As String) As VbMsgBoxResult

'If no Title then default to App Title
If sTitle = "" Then sTitle = Application.Name
'If showfor < minimum time then set to default
If ShowFor < tmMin Then ShowFor = tmDef

'Call Timer
ActivateMyTimer ShowFor
TmMsgBox = MsgBox(sMsg, Btn, sTitle)
DeActivateMyTimer

End Function

Sub aTest()
Dim Answer

Answer = TmMsgBox("Is this OK?", vbYesNo + vbDefaultButton1, , "Data Entry check")

'>> rest of your code if required

End Sub


Ivan F Moala is offline   Reply With Quote
Old Mar 1st, 2002, 02:33 AM   #9
Ivan F Moala
MrExcel MVP
 
Ivan F Moala's Avatar
 
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
Default

Ivan F Moala is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 11:07 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes