开发者

How does one close an opened file with a Windows script?

开发者 https://www.devze.com 2023-01-24 19:47 出处:网络
I want to set up a script to be run daily as a Wi开发者_开发技巧ndows Scheduled Task. The script should open an Excel spreadsheet, wait for it to run a macro (which is set up to run every time the spr

I want to set up a script to be run daily as a Wi开发者_开发技巧ndows Scheduled Task. The script should open an Excel spreadsheet, wait for it to run a macro (which is set up to run every time the spreadsheet is opened), and then close the file after the macro finishes saving the changes. The macro itself won't take very long to run. If my script can just wait for about a minute before closing the file again, that should be sufficient.


Completely untested code and mostly written from memory but hopefully enough to get you started:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消