Link to home
Start Free TrialLog in
Avatar of Pdeters
Pdeters

asked on

import csv file into Access via VBA

I am using the following code to import an Excel File. I need import a csv comma delimited. How how do I need to change this

    With fd
        .Title = "Select file for import"
        .Filters.Add "XLS File", "*.xls"
        .InitialFileName = INITIAL_FOLDER
        If .Show = -1 Then FilePath = .SelectedItems(1)
    End With
    Set fd = Nothing
     
        docmd.TransferSpreadsheet , acSpreadsheetTypeExcel3, "Table1", FilePath, True
Avatar of ruslanin
ruslanin

   With fd
        .Title = "Select file for import"
        .Filters.Add "XLS File", "*.xls"
        .InitialFileName = INITIAL_FOLDER
        If .Show = -1 Then FilePath = .SelectedItems(1)
    End With
    Set fd = Nothing

    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;" & FilePath, Destination:=Range("$A$1"))
        .Name = "CSV Data"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 65001
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = True
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
Avatar of Pdeters

ASKER

I am looing to pulli n a csv file

   docmd.TransferSpreadsheet , acSpreadsheetTypeExcel3, "Table1", FilePath, True

The file will be in the same format each time
ASKER CERTIFIED SOLUTION
Avatar of ruslanin
ruslanin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pdeters

ASKER

Thank you