Application.OnTime EarliestTime sending too many emails

nmk34

New Member
Joined
Apr 12, 2022
Messages
45
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I set an email to be send everyday at 6am using the following, where myvar1 is the time to start, example 06:00:00

Application.OnTime EarliestTime:=TimeValue(myvar1), Procedure:="MY_SendEmail_Example1", schedule:=True

then in he email sub, at the end and after email is send, i retrigger the schedule as follows:
Application.Wait Now + TimeSerial(0, 0, 60) ' wait a little bit to avoid sending too many emails.
Call ScheduleRetrigger

Public Sub ScheduleRetrigger()
If UserForm1.ChSchedule1.Value = True Then
Application.OnTime EarliestTime:=TimeValue(myvar1), Procedure:="MY_SendEmail_Example1", schedule:=True
End sub

If I wanted to stop sending emails i use:
Application.OnTime EarliestTime:=TimeValue(myvar1), Procedure:="MY_SendEmail_Example1", schedule:=False

myvar1 = Application.WorksheetFunction.Text(UserForm1.txbFirstScheduleTime, "hh:mm:ss")
UserForm1.txbFirstScheduleTime = myvar1
h = TimeValue(myvar1)
some times i get two emails, and some imes i get 4 or 6 emails
today i got 1st email at 6am, then at 6:01am, then at 6:02am, then at 6:03am.
i have many stations sending emails, and i do not want to flood outlook in office 365.
how can I change the code to get one email only at 6am or as soon as avialable?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I resolvesd this issue and i am getting one email and some times two at the most.
 
Upvote 0
Good to hear you resolved the issue.

If you would like to post the solution then it is perfectly fine to mark your post as the solution to help future readers. Otherwise, please do not mark a post that doesn't contain a solution.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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