Import csv macro that works on all excel versions from 2000 to 2013

catchg

New member
Joined
Mar 17, 2013
Messages
1
Reaction score
0
Points
0
I have a macro assigned button on "Sheet1" that imports a csv file into an existing worksheet named "Data" (cell F6). The macro works for excel versions 2007 and up. Unfortunately, I have users who have excel versions that span back to excel 2000. I need to have a macro that works for any version of excel since excel 2000. Any assistance would be appreciated. The macro I am currently using in excel 2010 follows:

Code:
Sub ImportCsvFile()

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("$F$6"))
        .Name = "CAPTURE"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = False
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = False
        .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
 
Back
Top