如何使用 Windows 任务计划程序为 xlsm 文件设置重复计划 [英] How to set recurring schedule for xlsm file using Windows Task Scheduler
本文介绍了如何使用 Windows 任务计划程序为 xlsm 文件设置重复计划的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 xlsx
启用宏的文件.如何在任务管理器中设置它,以便每天上午 9 点任务管理器打开工作簿,触发宏并关闭工作簿.
I have a xlsx
macro enabled file . How can I set it in the task manager so that everyday at 9 AM task manager would open the workbook, fire the macro and close the workbook.
到目前为止我正在使用
Application.OnTime ...
但我意识到保持 xlsm 文件打开很不方便
But i realize that keeping the xlsm file open is inconvenient
推荐答案
最好使用 vbs 如你所指
- 创建一个简单的
vbs
,它是一个带有 .vbs 扩展名的文本文件(参见下面的示例代码) - 使用任务计划程序运行
vbs
- 使用
vbs
在预定时间打开workbook
,然后:- 使用
ThisWorkbook
模块中的Private Sub Workbook_Open()
事件在打开文件时运行代码 - 更强大(因为宏可能在打开时被禁用),在
vbs
中使用Application.Run
来运行宏
- 使用
- 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 theworkbook
at the scheduled time and then either:- use the
Private Sub Workbook_Open()
event in theThisWorkbook
module to run code when the file is opened - more robustly (as macros may be disabled on open), use
Application.Run
in thevbs
to run the macro
- use the
示例 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
这篇关于如何使用 Windows 任务计划程序为 xlsm 文件设置重复计划的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文