Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am trying to have a Macro run automatically when a sheet is opened in
excel. Also would I need to put this code in for each spreadsheet designed for it to run or can just the main sheet trigger the macro to run on all sheets published or where should I put Sub Auto_Open() in the code below: Option Explicit Public Declare Function SetTimer Lib "user32" ( _ ByVal hwnd As Long, _ ByVal nIDEvent As Long, _ ByVal uElapse As Long, _ ByVal lpTimerfunc As Long) As Long Public 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 sTitle = "" Then sTitle = Application.Name If ShowFor < tmMin Then ShowFor = tmDef ActivateMyTimer ShowFor TmMsgBox = MsgBox(sMsg, Btn, sTitle) DeActivateMyTimer End Function Sub aTest() Dim Answer Answer = TmMsgBox("You have until 12:01 Thursday OK!", vbYesNo + vbDefaultButton1, , "Data Entry check") MsgBox Answer End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
On opening a file auto open another | Excel Programming | |||
Auto macro opening excel workbook | Excel Programming | |||
Auto opening of a EXcel file on a CD | Excel Programming | |||
Book 1 auto opening | Excel Programming | |||
Auto opening macro when loading a workbook | Excel Programming |