Consulting

Results 1 to 2 of 2

Thread: Import data from multiple CSV files on a Mac

  1. #1
    VBAX Newbie
    Joined
    Nov 2017
    Posts
    1
    Location

    Import data from multiple CSV files on a Mac

    I'm trying to import data from multiple CSV files in a single folder.

    I have an application that produces a changing number of CSV files with the same format, and I'm trying to create a macro to import them all to a single worksheet.

    I'm a newbie to VBA so I've started by looking for examples from around the web. The current code I'm using (not mine) is included below. It's giving me a "Device Unavailable" error.

    I'd be very grateful for any help!

    Thank you,
    Stuart



    Sub ImportAllCSV()
    Dim FName AsVariant, R AsLong
    R
    =1
    FName
    = Dir("*.csv")
    DoWhile FName <>""
    ImportCsvFile FName
    , ActiveSheet.Cells(R,1)
    R
    = ActiveSheet.UsedRange.Rows.Count +1
    FName
    = Dir
    Loop
    EndSub

    Sub ImportCsvFile(FileName AsVariant, Position As Range)
    With ActiveSheet.QueryTables.Add(Connection:= _
    "TEXT;"& FileName _
    , Destination:=Position)
    .Name = Replace(FileName,".csv","")
    .FieldNames =True
    .RowNumbers =False
    .FillAdjacentFormulas =False
    .RefreshOnFileOpen =False
    .BackgroundQuery =True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword =False
    .SaveData =True
    .AdjustColumnWidth =True
    .TextFilePromptOnRefresh =False
    .TextFilePlatform = xlMacintosh
    .TextFileStartRow =1
    .TextFileParseType = xlDelimited
    .TextFileTextQualifier = xlTextQualifierDoubleQuote
    .TextFileConsecutiveDelimiter =False
    .TextFileTabDelimiter =True
    .TextFileSemicolonDelimiter =False
    .TextFileCommaDelimiter =False
    .TextFileSpaceDelimiter =False
    .TextFileOtherDelimiter =","
    .TextFileColumnDataTypes = Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)
    .Refresh BackgroundQuery:=False
    EndWith
    EndSub

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Moderator Bump
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •