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
精彩评论