我有代碼,許多進口的文本文件,含有異物/特殊字符,到Excel工作簿:導入文本與外文字符
Sub loadfiles()
Dim fpath As String
Dim fname As String
Application.ScreenUpdating = False
fpath = "...\data\"
fname = Dir(fpath & "*.txt")
For i = 1 To 10
Application.StatusBar = True
Application.StatusBar = "Progress: " & i & " of 10000"
Sheet1.Select
Range("A" & i).Value = fname
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" _
& fpath & fname, Destination:=Range("B" & i))
.Name = "a"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileColumnDataTypes = _
Array(xlTextFormat, xlSkipColumn, xlGeneralFormat)
.Refresh BackgroundQuery:=False
fname = Dir
End With
Next i
Application.StatusBar = False
Application.ScreenUpdating = True
MsgBox "Done"
End Sub
有什麼辦法來導入文本不失原始字符?
謝謝。 .QueyType沒有工作,但改變後.TextFilePlatform它的工作。 – user2702405
我很高興它有幫助。請記住,「TextFilePlatform」依賴於** QueryType **(來自幫助):_僅當您的查詢表基於來自文本文件的數據時(使用QueryType屬性設置爲xlTextImport),才使用TextFilePlatform ._ –