且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Windows任务计划程序设置xlsm文件的重复计划

更新时间:2022-12-02 18:33:24

更好地使用 vbs 如你所说


  1. 创建一个简单的 vbs ,这是一个文本文件与 .vbs 扩展名(见下面的示例代码)

  2. 使用任务计划程序运行 vbs

  3. 使用 vbs 在预定的时间打开工作簿然后是:

    • ThisWorkbook中使用 Private Sub Workbook_Open()事件模块在文件打开时运行代码

    • 更强壮(因为宏可能在打开时被禁用),使用 Application.Run code code code $运行宏

  1. Create a simple vbs, which is a text file with a .vbs extension (see sample code below)
  2. Use the Task Scheduler to run the vbs
  3. 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

请参阅在Windows任务计划程序中运行Excel

样本vbs

Dim ObjExcel, ObjWB
Set ObjExcel = CreateObject("excel.application")
'vbs opens a file specified by the path below
Set ObjWB = ObjExcel.Workbooks.Open("C:\temp\rod.xlsm")
'either use the Workbook Open event (if macros are enabled), or Application.Run

ObjWB.Close False
ObjExcel.Quit
Set ObjExcel = Nothing