我想導出使用VBA以UTF-8 CSV格式創建的文件。從搜索留言板,我已發現下面的代碼,一個文件轉換爲UTF-8(from this thread):導出爲UTF-8 CSV文件(使用Excel-VBA)
Sub SaveAsUTF8()
Dim fsT, tFileToOpen, tFileToSave As String
tFileToOpen = InputBox("Enter the name and location of the file to convert" & vbCrLf & "With full path and filename ie. C:\MyFolder\ConvertMe.Txt")
tFileToSave = InputBox("Enter the name and location of the file to save" & vbCrLf & "With full path and filename ie. C:\MyFolder\SavedAsUTF8.Txt")
tFileToOpenPath = tFileToOpen
tFileToSavePath = tFileToSave
Set fsT = CreateObject("ADODB.Stream"): 'Create Stream object
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
fsT.LoadFromFile tFileToOpenPath: 'And write the file to the object stream
fsT.SaveToFile tFileToSavePath, 2: 'Save the data to the named path
End Sub
然而,這種代碼只轉換非UTF-8文件以UTF-8。如果我要將文件保存爲非UTF-8格式,然後將其轉換爲UTF-8格式,它將會丟失它包含的所有特殊字符,從而使這個過程毫無意義!
我正在做的是以UTF-8(CSV)格式保存一個打開的文件。有沒有辦法用VBA做到這一點?
n.b.我也在'ozgrid' forum上問過這個問題。如果我找到解決方案,將關閉這兩個線程。
我在這裏的例子將在Excel導出範圍爲UTF-8 CSV http://stackoverflow.com/questions/12352958/excel-vba-export-to-utf-8/12353832#12353832。有幾個更新,即轉換http,一個字符串或最後一個允許您指定一個範圍。 – user3357963
或給這個去http://www.mediafire.com/view/?zbngcy2sborbklm – user3357963
因爲我有完全相同的問題,我發現你的消息,之後,我在法國網站上找到答案! http://geek-mondain.blogspot.fr/2011/09/excel-et-son-incapacite-exporter-des.html它工作完美! –