How to export data into UTF-8 without BOM in Visual Basic


Create stream for UTF-8.

Set sqlStream = CreateObject("ADODB.Stream")
'Init stream
sqlStream.Open
sqlStream.Position = 0
sqlStream.Charset = "UTF-8"

Write your data into the stream.

Dim binaryStream As Object
Set binaryStream = CreateObject("ADODB.Stream")
binaryStream.Type = 1
binaryStream.Mode = 3
binaryStream.Open
'Skip BOM bytes
sqlStream.Position = 3
sqlStream.CopyTo binaryStream
sqlStream.Flush
sqlStream.Close
binaryStream.SaveToFile sqlFilename, 2
binaryStream.Close

Comments

  1. Thank you - you just saved my evening

    ReplyDelete
  2. Hello Spotty,
    I am looking for a macro in VBA that save my excel sheet1 into a txt file charset: UTF-8 without BOM
    I usually work with excel and have no much idea about macros, that's why I wonder if you could create the macro in vba for excel and post it here.
    Please I would be very gratefull if you could write the full code between Sub () and End Sub(). Send me an email joeypublic@gmail.com. Let me know what libraries do I have to activate in excel.
    Thanks Joe.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete

Post a Comment