Mac Excel使用VBA生成UTF-8

是否有可能在Excel 2016 for Mac中使用Visual Basic(VBA)生成一个UTF-8文件? 我需要生成一个编码的XML或TXT文件。

谢谢

不是UTF-8,但是UTF-16是VBA在内部使用的,所以你可以直接转储string数据:

 Dim fnum As Integer fnum = FreeFile() Open "utf16.txt" For Binary Access Write As fnum 'write UTF-16 Byte Order Marker ' Put #fnum, 1, &HFE Put #fnum, 2, &HFF printLineUtf16 fnum, "Olá Mundo!" Close #fnum Function printLineUtf16(fnum As Integer, str As String) str = str & ChrW(10) 'append newline Dim data() As Byte 'coerce string to bytes data = str Put #fnum, LOF(fnum) + 1, data 'append bytes to file End Function 

这应该在Excel的Mac 2011和2016,以及Windows版本。 请注意,您将无法在编辑器中键入Unicodestring文字,只是简单的重音拉丁字母(如上面的“á”),但是从单元格的Value分配的string将保留为Unicode。