Application.OnTime Issue

anichols

Board Regular
Joined
Mar 11, 2021
Messages
87
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have what seemed like simple vba code from Microsoft's website, but I am running into errors. I have a workbook where a userform opens when the workbook is started and a message prompts that a macro will run in 90 seconds unless the command button is clicked. Clicking the button gives me errors.

VBA Code:
Private Sub CommandButton1_Click()
Application.OnTime EarliestTime:=Now + TimeValue("00:01:30"), _
 Procedure:="Create_TheReport", Schedule:=False
Me.Hide
End Sub

Private Sub UserForm_Initialize()
Application.OnTime Now + TimeValue("00:01:30"), "Create_TheReport"
End Sub
Any assistance in where I've gone wrong would be helpful.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
The error message says what and fails on which line?
 
Upvote 0
The error message says what and fails on which line?
Run Time Error 1004 Method 'OnTime' of object '_Application' failed
This is highlighted:
VBA Code:
Application.OnTime EarliestTime:=Now + TimeValue("00:01:30"), _
 Procedure:="Create_TheReport", Schedule:=False
 
Upvote 0
Maybe try
Application.OnTime Now + TimeValue("00:01:30"), "Create_TheReport", False
Works for me, but what you posted doesn't. Not sure why
 
Upvote 0
Maybe try
Application.OnTime Now + TimeValue("00:01:30"), "Create_TheReport", False
Works for me, but what you posted doesn't. Not sure why
It did run without errors, however the Sub still gets called, which is what I'm trying to avoid :)
 
Upvote 0
Setting schedule parameter to false is supposed to stop it from running and this seems to be a common issue.
Here's one that's supposed to solve it - haven't studied it to determine why it would work. I find that what I have runs once, then stops, probably because of the false parameter. I tried using a variable for time and setting it to timevalue(0,0,0) but it seems once the code initializes the event, it doesn't stop it.
I'll probably play with it later to see if there's a way to do that because many posted solutions seem to involve a lot of code that you'd think unnecessary if you could just cancel the event.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top