Better to use a vbs as you indicated
- Create a simple
vbs
, which is a text file with a .vbs extension (see sample code below)
- Use the Task Scheduler to run the
vbs
- Use the
vbs
to open the workbook
at the scheduled time and then either:
- use the
Private Sub Workbook_Open()
event in the ThisWorkbook
module to run code when the file is opened
- more robustly (as macros may be disabled on open), use
Application.Run
in the vbs
to run the macro
See this example of the later approach at Running Excel on Windows Task Scheduler
sample vbs
Dim ObjExcel, ObjWB
Set ObjExcel = CreateObject("excel.application")
'vbs opens a file specified by the path below
Set ObjWB = ObjExcel.Workbooks.Open("C:emp
od.xlsm")
'either use the Workbook Open event (if macros are enabled), or Application.Run
ObjWB.Close False
ObjExcel.Quit
Set ObjExcel = Nothing
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…