如何使用 Windows 任务计划程序为 xlsm 文件设置重复计划 [英] How to set recurring schedule for xlsm file using Windows Task Scheduler

查看:41
本文介绍了如何使用 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

推荐答案

最好使用 如你所指

  1. 创建一个简单的 vbs,它是一个带有 .vbs 扩展名的文本文件(参见下面的示例代码)
  2. 使用任务计划程序运行vbs
  3. 使用 vbs 在预定时间打开 workbook,然后:
    • 使用ThisWorkbook 模块中的Private Sub Workbook_Open() 事件在打开文件时运行代码
    • 更强大(因为宏可能在打开时被禁用),在 vbs 中使用 Application.Run 来运行宏
  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:	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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆