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?
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.