mcarter973
Board Regular
- Joined
- Mar 24, 2002
- Messages
- 83
I have the following code (massaged from cpearson.com) - the workbook will remain open during business day - how can i utilize workbook_open to have "The_Sub" run when the user opens the workbook in the morning (instead of having the user run the macro every morning to start the timer)?
The file is reading real-time data from Bloomberg and will be updated and printed on the hour, every hour.
Thanks.
Public RunWhen As Double
Public Const cRunIntervalHour = 1 ' one hour
Public Const cRunWhat = "The_Sub"
Sub StartTimer()
RunWhen = TimeValue("12:00 AM") + TimeSerial(cRunIntervalHour, 0, 0)
Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
schedule:=True
End Sub
Sub The_Sub()
Range("B1").Value = Date
Range("B2").Value = Time
Columns("B:B").EntireColumn.AutoFit
StartTimer
ActiveWindow.SelectedSheets.PrintOut Copies:=1
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, _
procedure:=cRunWhat, schedule:=False
End Sub
The file is reading real-time data from Bloomberg and will be updated and printed on the hour, every hour.
Thanks.
Public RunWhen As Double
Public Const cRunIntervalHour = 1 ' one hour
Public Const cRunWhat = "The_Sub"
Sub StartTimer()
RunWhen = TimeValue("12:00 AM") + TimeSerial(cRunIntervalHour, 0, 0)
Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
schedule:=True
End Sub
Sub The_Sub()
Range("B1").Value = Date
Range("B2").Value = Time
Columns("B:B").EntireColumn.AutoFit
StartTimer
ActiveWindow.SelectedSheets.PrintOut Copies:=1
End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime earliesttime:=RunWhen, _
procedure:=cRunWhat, schedule:=False
End Sub