我正在使用以下宏(感谢The_Barman代码!)将CSV文件导入名为Tickets的工作表。问题是其中有一些特殊的字符,如Ü,Ä等,所以我需要以UTF-8格式导入文件。任何人都可以告诉我如何将其添加到此代码中吗?
提前致谢!
Sub CSV_Import()
Dim ws As Worksheet, strFile As String
Worksheets("Tickets").Range("A1:Z9999").Clear
Set ws = ActiveWorkbook.Sheets("Tickets")
strFile = "C:\test\testfile.csv"
With ws.QueryTables.Add(Connection:="TEXT;" & strFile, Destination:=ws.Range("A1"))
.TextFileParseType = xlDelimited
.TextFileCommaDelimiter = True
.Refresh
End With
End Sub
答案 0 :(得分:4)
我添加了#34; .TextFilePlatform = 65001"代码和它现在正在工作:
Sub CSV_Import()
Dim ws As Worksheet, strFile As String
Worksheets("Tickets").Range("A1:Z9999").Clear
Set ws = ActiveWorkbook.Sheets("Tickets")
strFile = "C:\test\testfile.csv"
With ws.QueryTables.Add(Connection:="TEXT;" & strFile, Destination:=ws.Range("A1"))
.TextFileParseType = xlDelimited
.TextFilePlatform = 65001
.TextFileCommaDelimiter = True
.Refresh
End With
End Sub