我正在尝试将文本文件自动导入Excel。似乎可以使用以下代码完美地导入,但是,如果我希望它将其导入到表中,则不会这样做,并导致表向右移动。
path = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(ThisWorkbook.path)
Sheets("Sheet1").Activate
Sheets("Sheet1").Select
Sheets("Sheet1").Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & path & "\Users
Roles Entitlements.csv", Destination:=Sheets("Sheet1").Range("A1"))
.Name = "positions_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 857
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
让我们假设表名是Table1。
如果有人可以建议对此代码进行修改,以便将其直接导入到Table1并相应地重新调整Excel表,将不胜感激。