【问题标题】:VBA Excel Macro write file using UTF-8 encoding [duplicate]使用 UTF-8 编码的 VBA Excel 宏写入文件 [重复]
【发布时间】:2012-06-27 13:42:41
【问题描述】:

我正在 excel 中创建一个宏来处理电子表格并将内容(文本)写入文件。我需要将此文件编码为 UTF-8。我尝试使用 OpenTextFile(... TristateTrue) 和 StrConv(.. vbUnicode) 将文件作为 unicode 打开,但这些仅将其转换为 UTF-16。我在网上到处搜索,找不到任何东西。这甚至可能吗?

谢谢

【问题讨论】:

标签: excel vba unicode utf-8


【解决方案1】:
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

参考: Save text file UTF-8 encoded with VBA

【讨论】:

  • 如果您引用另一个 SO 答案,那么最好将其标记为重复。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-07-07
  • 1970-01-01
  • 2011-07-22
  • 2019-10-06
  • 2011-02-01
相关资源
最近更新 更多