我正在尝试使用VBA函数从用户指定的路径打开文件。
当我将文件的内容粘贴到所需的工作表时,它会在工作表中粘贴一些奇怪的无法识别的字符。任何人都可以弄清楚我做错了什么?
这是我的代码:
Sub x_Macro()
'****************Declaring relevant variables****************'
Dim t As Range
Dim path: path = Application.GetOpenFilename("XLS Files (*.xls), *.xls")
Dim cht1 As ChartObject
'Dim button_click As VbMsgBoxResult
Application.ScreenUpdating = False
Sheets(2).Activate
If path = False Then Exit Sub
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & path, Destination:=Range("A1"))
.FieldNames = True
.RowNumbers = True
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With