【问题标题】:Import CSV using UTF-8使用 UTF-8 导入 CSV
【发布时间】:2017-10-09 03:04:09
【问题描述】:

我正在使用以下宏(感谢 The_Barman 提供代码!)将 CSV 文件导入到名为门票的工作表中。问题是其中有一些特殊字符,如Ü,Ä等,所以我需要以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

【问题讨论】:

标签: excel vba csv utf-8


【解决方案1】:

我在代码中添加了“.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

【讨论】:

  • 我不得不放 65000。
猜你喜欢
  • 2013-06-13
  • 2012-11-18
  • 1970-01-01
  • 1970-01-01
  • 2016-02-07
  • 2011-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多