macro to Import csv file into an excel non active worksheet

前端 未结 2 907
你的背包
你的背包 2021-02-01 10:46

I have a macro enabled excel workbook that contains several named worksheets. One of the worksheets is named \"panel\" and a second worksheet is named \"data\". The sheet named

2条回答
  •  广开言路
    2021-02-01 11:22

    Is this what you are trying?

    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:=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
    

提交回复
热议问题