如何使用Windows脚本关闭打开的文件?

时间:2010-11-09 20:01:47

标签: windows windows-scripting

我想设置一个每天作为Windows计划任务运行的脚本。该脚本应该打开一个Excel电子表格,等待它运行一个宏(设置为每次打开电子表格时运行),然后在宏完成保存更改后关闭该文件。宏本身不会花很长时间才能运行。如果我的脚本可以在再次关闭文件之前等待大约一分钟,那就足够了。

1 个答案:

答案 0 :(得分:2)

完全未经测试的代码,大多是从内存中编写的,但希望足以让您入门:

Set app = GetObject(, "Excel.application") ' assumes Excel is already running, otherwise use Set app = CreateObject("Excel.Application")
app.Visible = True ' useful while testing
app.run "MyMacro", "Param1" ' run the MyMacro macro with a string parameter "Param1"
WScript.Sleep(60000) ' wait 60,000 ms = 1 minute
app.ActiveDocument.Close
app.Quit
Set app = Nothing
相关问题