I have an excel sheet that is opened every day at 7am by the Windows task scheduler.
The sheet has the following code (in the "ThisWorkbook"Code) that calls the VBA code after waiting 1 minute (this time is needed until all links are updated):
Private Sub Workbook_BeforeClose(Cance
l As Boolean)
Application.OnTime dTime, "RunVbaOnTime", , False
Private Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:01:00"), "RunVbaOnTime"
This here is in addition added to a Module:
Public dTime As Date
dTime = Now + TimeValue("00:01:00")
Application.OnTime dTime, "RunVbaOnTime"
which then calls after 1 minute the code below SendDailyFxByEmailToServer
However, somehow the application does not properly close/quit. While the sheet is closed, the code continues to send the email every 1 minute until excel is manually closed. Any help to change this code in order it works, i.e. quits excel entirely?
Application.ScreenUpdating = False
' Select the range of cells on the active worksheet and copy paste values
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
' Show the envelope on the ActiveWorkbook.
ActiveWorkbook.EnvelopeVisible = True
' Set the To and Subject lines and send out msg
.Item.To = "firstname.lastname@example.org"
.Item.Cc = "email@example.com"
.Item.Subject = " Daily Fx Feed"
' closes the active workbook without saving any changes, exit application
Application.ScreenUpdating = True