vba 使用vbs打开excel工作簿,运行宏并保存工作簿
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29325804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:30:04 来源:igfitidea点击:
Use vbs to open an excel workbook, run a macro and save the workbook
提问by ALEXM
- I have a macro that I need to be run every 5 min. I have a
vbsfile that schedules the macro. - The macro is checking for new files in some folder, writes their info into a table, and moving the files into archive.
- The table is in the same excel file as the macro!
- 我有一个需要每 5 分钟运行一次的宏。我有一个
vbs安排宏的文件。 - 该宏正在检查某个文件夹中的新文件,将它们的信息写入表格,并将文件移动到存档中。
- 该表与宏在同一个excel文件中!
It is running the macro fine but in the end, its asking me if I wont to save the file.
它运行宏很好,但最后,它问我是否不保存文件。
I need it to save the changes that the macro did to the file automatically!
我需要它来自动保存宏对文件所做的更改!
this is my current vbscode:
这是我当前的vbs代码:
Option Explicit
Dim xlApp, xlBook
Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
Set xlBook = xlApp.Workbooks.Open("W:\Excel Macro\EIM File Maneger\EIM_file_check.xlsm", 0, True)
xlApp.Run "GetFiles"
xlBook.Close true
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing
WScript.Echo "Finished."
WScript.Quit
回答by brettdj
Updated code below, I have also tweaked the logic of the clean-up
更新了下面的代码,我还调整了清理的逻辑
Dim xlApp, xlBook
Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
Set xlBook = xlApp.Workbooks.Open("W:\Excel Macro\EIM File Maneger\EIM_file_check.xlsm", 0, True)
xlApp.Run "GetFiles"
xlbook.Save
xlBook.Close False
set xlBook = Nothing
xlApp.Quit
Set xlApp = Nothing
WScript.Echo "Finished."
WScript.Quit

