I'm working on the following macro in excel, which loops through all of the Worksheets in a Workbook and saves each to its own .csv file. The issue is that I need it to save as a .csv encoded with UTF-8. I read that Excel's default encoding for .csv is ANSI, which won't work for me because I have some files with special characters in them. Does anyone know how I can go about this?
The macro:
Public Sub ExportSheetsToCSV()
Dim wsExport As Worksheet
Dim wbkExport As Workbook
For Each wsExport In Worksheets
wsExport.Select
nm = wsExport.Name
If Not IsActiveSheetEmpty() Then ActiveSheet.SaveAs fileName:="H:\CSV_Split_Exports\" & nm, FileFormat:=xlCSV Application.DisplayAlerts = True
End If
Next wsExport
End Sub 1 Answer
The "easy way" is to save as "Unicode Text." This will be UTF-16, tab delimited format, rather than comma delimited.
Most software import processes allows you to specify the delimiter when importing the data, but if your particular application does not, you can post-process the file with a find+replace to change the tab to a comma.
5