2

I need to convert "ANSI" csv file to "UTF-8" csv file. Below code can work, but the first character miss Please see attached screen shot, the original file : Customer the output file : 﨏ustomer

Function Convert(myFileIn, myFileOut)
  Dim stream ,strTextText
  Set stream = CreateObject("ADODB.Stream")

  stream.Open
  stream.Type = 2 'text
  stream.LoadFromFile myFileIn
  stream.Position = 0
  stream.Charset = "gb2312"
  strText = stream.ReadText
  stream.Close

  stream.Open
  stream.Type = 2
  stream.Position = 0
  stream.Charset = "utf-8"
  stream.WriteText strText
  stream.SaveToFile myFileOut, 2
  stream.Close
  Set stream = Nothing

End Function

enter image description here

maomifadacai
  • 357
  • 2
  • 4
  • 17

1 Answers1

8

You have to set

stream.Type

and

stream.Charset

before you open the stream.

And stream.Position is 0 by default.

Greetings

Axel

Axel Richter
  • 56,077
  • 6
  • 60
  • 87