2016-02-18 54 views
0

我有一个导入.csv文件到工作表“数据”导入多个CSV文件导入到主Excel表格中的数据追加到以前的进口

首次导入后的脚本以下所有的人出现的正确的以前的进口并没有添加到底部(最后一行)。

我认为这个问题涉及到这方面的脚本: 目的地:= ThisWorkbook.Sheets( “数据”)范围( “$ A $ 1”))

Sub load_csv() 
    Dim fStr As String 

    With Application.FileDialog(msoFileDialogFilePicker) 
     .Show 
     If .SelectedItems.Count = 0 Then 
      MsgBox "Cancel Selected" 
      Exit Sub 
     End If 
     'fStr is the file path and name of the file you selected. 
     fStr = .SelectedItems(1) 
    End With 

    With ThisWorkbook.Sheets("Data").QueryTables.Add(Connection:= _ 
    "TEXT;" & fStr, Destination:=ThisWorkbook.Sheets("Data").Range("$A$1")) 
     .Name = "CAPTURE" 
     .FieldNames = True 
     .RowNumbers = False 
     .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 = False 
     .TextFileCommaDelimiter = True 
     .TextFileSpaceDelimiter = False 
     .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) 
     .TextFileTrailingMinusNumbers = True 
     .Refresh BackgroundQuery:=False 

    End With 
End Sub 
+0

你看过本网站上已解决此问题的答案吗? – Jeeped

回答

0

您需要检查目标看看下一个未使用的单元是什么。

With ThisWorkbook.Sheets("Data") 
    .QueryTables.Add(Connection:= _ 
    ..., Destination:=.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0) 
'lots of other stuff 
End With 

可以rereference反复ThisWorkbook.Sheets( “数据”),但使用With ... End With statement更容易。