Export sheet as UTF-8 CSV file (using Excel-VBA)

后端 未结 3 1244
小鲜肉
小鲜肉 2020-12-16 07:17

I would like to export a file I have created in UTF-8 CSV using VBA. From searching message boards, I have found the following code that converts a file to UTF-8 (from this

3条回答
  •  盖世英雄少女心
    2020-12-16 07:41

    Finally in Office 2016, you can simply savs as CSV in UTF8.

    Sub SaveWorkSheetAsCSV()
    
    Dim wbNew As Excel.Workbook
    Dim wsSource As Excel.Worksheet, wsTemp As Excel.Worksheet
    Dim name As String
    
    
    
        Set wsSource = ThisWorkbook.Worksheets(1)
        name = "test"
        Application.DisplayAlerts = False 'will overwrite existing files without asking
        Set wsTemp = ThisWorkbook.Worksheets(1)
        Set wbNew = ActiveWorkbook
        Set wsTemp = wbNew.Worksheets(1)
        wbNew.SaveAs name & ".csv", xlCSVUTF8 'new way
        wbNew.Close
        Application.DisplayAlerts = True
    
    End Sub
    

    This will save the worksheet 1 into csv named test.

提交回复
热议问题