June 27th, 2012, 08:49 AM
VBA Excel Macro write file using UTF-8 encoding
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?
June 27th, 2012, 09:49 AM
Re: VBA Excel Macro write file using UTF-8 encoding
I know of nothing in Excel VBA that can do that and didn't find a Win32 API function for that either. However, actually UTF-8 isn't really so complicated. You can use StrConv() to first convert to UTF-16 and from there do the conversion to UTF-8 yourself. AFAICT Windows doesn't use any Unicode characters beyond the Basic Multilingual Plane anyway, which allows you to simply take the byte pairs from the UTF-16 encoding for Unicode codepoints, simpifying things a bit more.
Eventually, looks like it's a matter of how much effort you want to take for the UTF-8 output.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.