Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run time error
I get the following error when I close the spreadsheet
Run Time error 1004 Method on time of object _application failed Help! here's the code in debug Private Sub Workbook_BeforeClose(Cancel As Boolean) Application.OnTime EarliestTime:=TimeValue("00:00:10"), _ Procedu="Total", Schedule:=False End Sub Private Sub Workbook_Open() Application.OnTime Now + TimeValue("00:00:10"), "Total" End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run time error
After serious thinking MB wrote :
I get the following error when I close the spreadsheet Run Time error 1004 Method on time of object _application failed Help! here's the code in debug Private Sub Workbook_BeforeClose(Cancel As Boolean) Application.OnTime EarliestTime:=TimeValue("00:00:10"), _ Procedu="Total", Schedule:=False End Sub Private Sub Workbook_Open() Application.OnTime Now + TimeValue("00:00:10"), "Total" End Sub Why are you putting a delay when to run "Total" at shutdown if there's no schedule as to when? VBA doesn't wait for OnTime statements; it just executes them at the time specified. In this case that happens after the workbook has already closed and so the error is raised because the macro is not available any longer. I'd just run the macro like this: Call Total -- Garry Free usenet access at http://www.eternal-september.org ClassicVB Users Regroup! comp.lang.basic.visual.misc |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Run time error
GS has brought this to us :
After serious thinking MB wrote : I get the following error when I close the spreadsheet Run Time error 1004 Method on time of object _application failed Help! here's the code in debug Private Sub Workbook_BeforeClose(Cancel As Boolean) Application.OnTime EarliestTime:=TimeValue("00:00:10"), _ Procedu="Total", Schedule:=False End Sub Private Sub Workbook_Open() Application.OnTime Now + TimeValue("00:00:10"), "Total" End Sub Why are you putting a delay when to run "Total" at shutdown if there's no schedule as to when? VBA doesn't wait for OnTime statements; it just executes them at the time specified. In this case that happens after the workbook has already closed and so the error is raised because the macro is not available any longer. I'd just run the macro like this: Call Total Ok, I get it! I now see you started OnTime at startup and are just turning it off here. My understanding of using this function is that the time AND procedure must match. I suggest you store your startup time in a variable and use that as the value for EarliestTime: '**Place in Declarations section of standard module** Public OnTimeStart Private Sub Workbook_Open() OnTimeStart = Now() + TimeValue("00:00:10") Application.OnTime OnTimeStart, "Total" End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) Application.OnTime _ EarliestTime:=OnTimeStart, Procedu="Total", Schedule:=False End Sub -- Garry Free usenet access at http://www.eternal-september.org ClassicVB Users Regroup! comp.lang.basic.visual.misc |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
run time error 1004 general odbc error excel 2003 vba | Excel Programming | |||
Visual Basic Error Run Time Error, Type Mismatch | Excel Discussion (Misc queries) | |||
Error handling error # 1004 Run-time error | Excel Programming | |||
Conditional Formatting - Run Time Error '13' Type Mismatch Error | Excel Programming | |||
run-time error '1004': Application-defined or object-deifined error | Excel Programming |