Excel VBA - export to UTF-8

来源:互联网 发布:0基础学c语言 编辑:程序博客网 时间:2024/06/05 01:14
    Dim filePath As String
    Dim fileName As String
    Dim charToEncode As String
    Dim encodingType As String
    Dim success As Boolean
    Dim rngArray() As Variant

    filePath = "C:\"
    fileName = "testUnicode.csv"
    encodingType = "utf-8"
    
    Dim startRow As Long
    Dim endRow As Long
    startRow = 2
    endRow = Range("A65536").End(xlUp).Row
   
    
    Set adodbStream = CreateObject("ADODB.Stream")
    With adodbStream
        .Type = 2 'Stream type
        .Charset = "UTF-8"
        'or utf-16 etc
        .Open
         .WriteText Sheet1.Cells(i, 1).Value
        .SaveToFile filePath & fileName, 2 'Save binary data To disk

    End With

end sub