0

これが私のコードで、アクティブなワークシートの最後の空白にデータを挿入できないことを除いて、すべてが機能します。

Sub load_csv()
    
    Dim fStr As String
    Dim nextrow As Long

    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
    
    Set nextrow = Range(Cells(Rows.Count, "A").End(xlUp).Row + 1) ' THIS IS FAILING

    With ThisWorkbook.Sheets("TEST").QueryTables.Add(Connection:= _
    "TEXT;" & fStr, Destination:=**nextrow**)
        .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
4

1 に答える 1

1
Set nextrow = Cells(Rows.Count, "A").End(xlUp).Offset(1)
于 2013-10-30T20:47:16.107 に答える