Reputation: 111
I have a macro and i will run that macro automatically, always on the same time on Monday to Friday. I have already a macro but that runs one time after opening the file. How to get repeat every day until saterday and sunday?
Public Sub Workbook_Open()
Dim dtmStarttijd As Date
dtmStarttijd = TimeSerial(7, 10, 0)
' Is de macro gestart?
MsgBox "De macro voor het automatisch starten van de procedure is gestart."
Application.OnTime dtmStarttijd, "sDeUitTeVoerenMacro"
End Sub
Kind regards Freek
Upvotes: 2
Views: 6537
Reputation: 2176
To start a macro at given time and on weekdays should this work:
Sub test()
If Weekday(Now, vbMonday) < 6 Then 'check if weekday is < 6, starting by Monday with 1 (Sat = 6, Sun = 7)
Application.OnTime TimeValue("00:01:10"), "YourSub"
End If
End Sub
Change TimeValue("00:01:10")
when the macro should start
Change "YourSub"
with your sub, e.g. your sub is named Sub timestart()
put in "timestart"
(without () but "" are needed!)
Excel has to be started for working
Upvotes: 1
Reputation: 6216
I set mine as scheduled tasks in windows and make it run in a safe mode copy of Excel with a quit at the end of the macro.
Make sure you do workbook.saved = true before quitting to suppress the prompt.
Upvotes: 0