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?
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?