I have an VBS Script converting an excel file to csv format called by a SQL server. It contains:
Set objExcel = CreateObject("Excel.Application
Set objBook = objExcel.Workbooks.Open(objFile.Path, , True)
objBook.Worksheets(i).Activate
objBook.SaveAs file_out_start & i & ".csv", 6, , , True, False, , , , , , True
This returns a csv file encoded in ANSI. To further process the file I need the output to be in UTF-8 encoding.
Following the Microsoft documentation here and here , I tried changing the parameter 6
to 62
representing 'UTF8 CSV'. With this change the script stops working exiting with following error:
line: 36 (line of 'objBook.SaveAs')
error: The SaveAs method of the Workbooks object could not be executed. (translated)
Code: 800A03EC
source: Microsoft Excel
Can anyone help why this happens? If it is not possible to export with UFT-8 encoding directly is there a easy way to convert the files to UFT-8 afterward in the script?
1条答案
按热度按时间ccrfmcuu1#
I had a similar issue. I think the issue is Excel can only save a WorkSheet as a csv, not a WorkBook, and therefore needs to use Worksheet.SaveAs instead of Workbook.SaveAs. My code is below.
Link to Worksheet.SaveAs: https://learn.microsoft.com/en-us/office/vba/api/excel.worksheet.saveas