LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Auto Opening for Macro

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
On opening a file auto open another Kevryl Excel Programming 4 May 15th 07 08:53 AM
Auto macro opening excel workbook Baris Excel Programming 2 July 27th 05 12:41 PM
Auto opening of a EXcel file on a CD Larry[_14_] Excel Programming 1 October 19th 04 02:37 PM
Book 1 auto opening Mark Goulty Excel Programming 2 June 16th 04 09:45 AM
Auto opening macro when loading a workbook Mike Boardman Excel Programming 4 May 8th 04 07:42 AM


All times are GMT +1. The time now is 08:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"