3

I'm creating a macro in excel that processes a spreadsheet and writes the content (text) to a file. I need this file to be encoded as UTF-8. I've tried opening the file as unicode using OpenTextFile(... TristateTrue) and StrConv(.. vbUnicode) but those only convert it to UTF-16. I've searched everywhere online and can't find anything. Is this even possible?

thanks

Chrismas007
  • 6,085
  • 4
  • 24
  • 47
jasonhughes
  • 33
  • 1
  • 1
  • 4
  • Searching for VBScript/VB6 which are very closely related is often helpful; http://stackoverflow.com/questions/4125778/unicode-to-utf-8 – Alex K. Jun 27 '12 at 13:57
  • thanks! that worked. I'm new to vb so i didn't know you could use the same command for it – jasonhughes Jun 27 '12 at 15:22

1 Answers1

2
Dim fsT As Object
Set fsT = CreateObject("ADODB.Stream")
fsT.Type = 2 'Specify stream type - we want To save text/string data.
fsT.Charset = "utf-8" 'Specify charset For the source text data.
fsT.Open 'Open the stream And write binary data To the object
fsT.WriteText "special characters: äöüß"
fsT.SaveToFile sFileName, 2 'Save binary data To disk

Reference: Save text file UTF-8 encoded with VBA

Community
  • 1
  • 1
Jose Ortega
  • 1,002
  • 13
  • 23