Read CSV UTF8 correctly in excel

YasserKhalil
PlatinumLounger
Posts: 4913
Joined: 31 Aug 2016, 09:02

Re: Read CSV UTF8 correctly in excel

Post by YasserKhalil »

I could figure it out after several tries and after a lot of search

Code: Select all

Sub MyTest()
    Dim myStrm As Object, objStream As Object, sFolder As String, txt As String
    sFolder = ThisWorkbook.Path & "\"
    Set myStrm = CreateObject("ADODB.Stream")
    With myStrm
        .Type = 2
        .Charset = "UTF-8"
        .Open
        .LoadFromFile sFolder & "Output.csv"
        txt = .ReadText
    End With
    Set objStream = CreateObject("ADODB.Stream")
    With objStream
        .Charset = "UTF-8"
        .Open
        .WriteText txt
        .SaveToFile sFolder & "OutputNew.csv", adSaveCreateOverWrite
    End With
End Sub
Thanks a lot my tutor for your great and awesome efforts to help others.