Excel 2011 VBA for Mac 中是否有 Scripting.FileSystemObject 的替代方案?
如何我可以在 Excel 2011 for MAC 中安装/使用“Scripting.FileSystemObject”吗? 似乎表明在 Excel 2010 for Mac 中使用Scripting.FileSystemObject
不可能的。
还有什么其他替代方案可供使用,以便我可以:
- 获取特定目录中所有 Excel 文件的集合
- 迭代每个文件中的每个工作表并导出它到 .csv 文件
目前,每个文件都有一个六步过程:
--how to create CSV files for all worksheets in a file:
1. open file
2. click "Developer"
3. click editor
4. click ThisWorkbook
5. copy in:
Sub save_all_csv()
On Error Resume Next
Dim ExcelFileName As String
ExcelFileName = ThisWorkbook.Name
For Each objWorksheet In ThisWorkbook.Worksheets
Filename = "FILE-" & ExcelFileName & "-WORKSHEET-" & objWorksheet.Name & ".csv"
objWorksheet.SaveAs Filename:="Macintosh HD:Users:edward:Documents:temporaryNoBackup:" & Filename, FileFormat:=xlCSV, CreateBackup:=False
Next
Application.DisplayAlerts = False
Application.Quit
End Sub
6. click run (it closes by itself)
我正在寻找一种自动化方法理想情况下,Mac 上的一个(cron 作业?、服务?)将每 10 分钟打开一次 Excel 文件,然后依次查看目录,将所有其他 Excel 文件转换为 .csv 文件,然后自行关闭。
如果没有 Scripting.FileSystemObject,如何在 Mac 上全自动进行 Excel 到 CSV 的转换?
The answers to How can I install/use “Scripting.FileSystemObject” in Excel 2011 for MAC? seem to indicate that using Scripting.FileSystemObject
in Excel 2010 for the mac is not possible.
What other alternative is available so I can:
- get a collection of all Excel files in a specific directory
- iterate through each worksheet within each file and export it to a .csv file
Currently this is a six-step process for each file:
--how to create CSV files for all worksheets in a file:
1. open file
2. click "Developer"
3. click editor
4. click ThisWorkbook
5. copy in:
Sub save_all_csv()
On Error Resume Next
Dim ExcelFileName As String
ExcelFileName = ThisWorkbook.Name
For Each objWorksheet In ThisWorkbook.Worksheets
Filename = "FILE-" & ExcelFileName & "-WORKSHEET-" & objWorksheet.Name & ".csv"
objWorksheet.SaveAs Filename:="Macintosh HD:Users:edward:Documents:temporaryNoBackup:" & Filename, FileFormat:=xlCSV, CreateBackup:=False
Next
Application.DisplayAlerts = False
Application.Quit
End Sub
6. click run (it closes by itself)
I'm looking for a way to automate this on the Mac, ideally, a (cron job?, service?) would open the excel file every 10 minutes, which would in turn look in a directory, convert all the other Excel files to .csv files, and then close by itself.
Without Scripting.FileSystemObject, how can I make this Excel-to-CSV conversion fully automatic on the Mac?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能想到的唯一方法是使用“Dir”功能。由于 mac 支持文件名中的额外字符,因此通配符不适用于“Dir”函数。这是一个示例。
The only way I can think of is using the "Dir" function. Since mac supports extra characters in their filenames, wildcards do not work with the "Dir" function. Here is a sample.
您可以将 VBA 放入附加到 Excel 本身(而不是工作簿)的加载项(.xlam 文件)中。对于您的示例代码,唯一的修改是针对
ActiveWorkbook
而不是ThisWorkbook
进行编写。您还可以利用 auto_open() 自动绑定热键。完成后,您只需打开工作簿,按热键即可获取 CSV 文件。
You can put the VBA in an add-in (.xlam file) that is attached to Excel itself, rather than the workbook. For your example code, the only modification would be to write against
ActiveWorkbook
instead ofThisWorkbook
.You can also leverage auto_open() to automate binding a hotkey. Once that's done, you can just open a workbook, press a hotkey, and get your CSV files.