简体   繁体   English

使用vbs打开Excel工作簿,运行宏并保存工作簿

[英]Use vbs to open an excel workbook, run a macro and save the workbook

  • I have a macro that I need to be run every 5 min. 我有一个宏,我需要每5分钟运行一次。 I have a vbs file that schedules the macro. 我有一个调度宏的vbs文件。
  • 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! 该表与宏在同一个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 vbs code: 这是我目前的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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM