且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何打开所有的Excel文件,并运行一个宏

更新时间:2023-09-14 11:20:52

By calling the Dir() function with an appropriate filter, such as "c:\folder\*.xls", you start enumeration and get the first file name.
After that, repeatedly calling the Dir() function without any parameters, you will get all *.xls file names, one for each call.

You open a workbook by calling Workbooks.Open(full_path). This gives you a Workbook object, against which you can run a macro.

The .Close() method of this Workbook object closes the workbook. You can use .Close(SaveChanges:=True) to save changes, .Close(SaveChanges:=False) to discard changes, or omit the parameter to have the user decide.

相关阅读

推荐文章