使用vbs打开excel工作簿,运行宏并保存工作簿 [英] Use vbs to open an excel workbook, run a macro and save the workbook
本文介绍了使用vbs打开excel工作簿,运行宏并保存工作簿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 我有一个宏,需要每5分钟运行一次.我有一个
vbs
文件来安排宏. - 宏正在检查某个文件夹中的新文件,将其信息写入表中,然后将文件移至存档中.
- 表与宏位于同一excel文件中!
- I have a macro that I need to be run every 5 min. I have a
vbs
file 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!
它可以很好地运行宏,但最后,它询问我是否要保存文件.
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!
这是我当前的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
推荐答案
下面更新了代码,我也调整了清理逻辑
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
这篇关于使用vbs打开excel工作簿,运行宏并保存工作簿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文