2012-06-27 228 views
1

我在Excel中創建了一個處理電子表格並將內容(文本)寫入文件的宏。我需要這個文件被編碼爲UTF-8。我試圖打開文件作爲unicode使用OpenTextFile(... TristateTrue)和StrConv(.. vbUnicode),但這些只能將其轉換爲UTF-16。我在網上到處搜索,找不到任何東西。這甚至有可能嗎?使用UTF-8編碼的VBA Excel宏寫入文件

感謝

+0

搜索的VBScript/VB6這是非常密切的關係往往是有幫助的; http://stackoverflow.com/questions/4125778/unicode-to-utf-8 –

+0

謝謝!那工作。我是vb的新手,所以我不知道你可以使用它相同的命令 – jasonhughes

回答

0
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

+1

如果你正在引用另一個SO答案,那麼這可能是最好的標記爲重複。 – Chrismas007