【发布时间】:2011-06-10 23:57:39
【问题描述】:
我有以下 Excel VBA 脚本,我在 Excel for Mac 2011 中使用该脚本将 Excel 文件的所有工作表导出到 .csv 文件。
Sub save_all_csv()
On Error Resume Next
Dim ExcelFileName As String
ExcelFileName = ThisWorkbook.Name
For Each objWorksheet In ThisWorkbook.Worksheets
ExcelFileNameWithoutExtension = RemoveExtension(ExcelFileName)
CsvFileName = ExcelFileNameWithoutExtension & "__" & objWorksheet.Name & ".csv"
Application.DisplayAlerts = False
objWorksheet.SaveAs Filename:="data:storage:original_excel:" & CsvFileName, FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = True
Next
Application.DisplayAlerts = False
Application.Quit
End Sub
Function RemoveExtension(strFileName As String)
strFileName = Replace(strFileName, ".xlsx", "")
strFileName = Replace(strFileName, ".xls", "")
RemoveExtension = strFileName
End Function
问题是它们保存为 Western Mac OS Roman,我无法通过 PHP 转换为 UTF-8,所以我想让 VBA 将这些文件保存为 UTF-8首先是格式。
我找到了一些通过 Stream 对象和 CreateObject 从 VBA 保存文本的解决方案,但它是 apparently not possibile on the Mac to use CreateObject to write directly to files。
如何使用 Excel for Mac 2011 将工作表保存为 UTF-8 格式的 CSV 文件?
【问题讨论】:
-
您是否尝试过使用
FileFormat:=xlCSVUTF8?