Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default 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
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
run time error 1004 general odbc error excel 2003 vba Mentos Excel Programming 5 January 24th 11 02:56 PM
Visual Basic Error Run Time Error, Type Mismatch Meg Partridge Excel Discussion (Misc queries) 12 September 10th 08 06:10 PM
Error handling error # 1004 Run-time error [email protected] Excel Programming 3 May 20th 08 02:23 PM
Conditional Formatting - Run Time Error '13' Type Mismatch Error ksp Excel Programming 0 July 11th 06 07:06 AM
run-time error '1004': Application-defined or object-deifined error [email protected] Excel Programming 5 August 10th 05 09:39 PM


All times are GMT +1. The time now is 01:59 PM.

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

About Us

"It's about Microsoft Excel"