我找到了这段代码,并尝试对其进行更改,以便将导入的数据存储在另一张表中。
第一个代码是Destination:=ActiveCell
,我尝试更改它,以便将数据存储在另一张表中。我也试过这个:Destination:=Workbook.Sheets(CSV).Cells(1, 1))
但它也不起作用。
我也在寻找代码来自动选择名为 export-price 的最新 csv 文件,但我还没有找到解决方案。
Sub LoadProducts()
Dim fileName As String, folder As String
folder = "C:\Users\CP\Downloads\"
fileName = ActiveCell.Value
ActiveCell.Offset(1, 0).Range("A1").Select
With ActiveSheet.QueryTables _
.Add(Connection:="TEXT;" & folder & fileName, Destination:=Workbook.Sheets(CSV).Cells(1, 1))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub