HalfAce
MrExcel MVP
- Joined
- Apr 6, 2003
- Messages
- 9,456
OK, I have an Application.OnTime situation that's kicking my a$$ and I'm ready to concede defeat.
I know what the problem is, and what needs to be done to solve it, but can't get it to work.
I'm using the following in my Workbook_Open and it works great.
This workbook is being used as a template file that gets saved under a different name every day. Now as we all know, it will open the workbook if needed to perform this routine at two minutes after midnight and since I can't have hunderds of workbooks trying to do this all at once, I need to turn the OnTime routine off when the workbook gets closed. That's where I'm having the problem.
I have tried many variations including the following, which, either one it seems to me, should work.
And...
The error I'm getting when I try to close the workbook is:
Run-time error '1004':
Method 'OnTime' of object '_Application' failed
Can someone please tell me where I'm going wrong?
Thanks very much,
Dan
I know what the problem is, and what needs to be done to solve it, but can't get it to work.
I'm using the following in my Workbook_Open and it works great.
Code:
Private Sub Workbook_Open()
Application.OnTime TimeValue("00:02:00"), "EnterPmLoads"
End Sub
I have tried many variations including the following, which, either one it seems to me, should work.
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnTime EarliestTime:=TimeValue("00:02:00"), _
Procedure:="EnterPmLoads", Schedule:=False
End Sub
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.OnTime EarliestTime:=Now(), _
Procedure:="EnterPmLoads", Schedule:=False
End Sub
Run-time error '1004':
Method 'OnTime' of object '_Application' failed
Can someone please tell me where I'm going wrong?
Thanks very much,
Dan