+ Reply to Thread
Results 1 to 2 of 2

How to import a .csv file?

  1. #1
    Registered User
    Join Date
    09-23-2004
    Posts
    2

    How to import a .csv file?

    Hi there,

    I was wondering what I did wrongly.
    I wanna run a loop so that it'll import all the .csv files onto different sheets in a workbook.

    What i did is, I put a list of "names" in column A of sheet1, and told it to import the files with the SAME "names" from a specific folder, say "c:\comics" . However, I keep getting this error:

    Run-time error '1004':
    Excel cannot find the text file to refresh this external data range.
    Check to make sure the text file has not been moved or renamed, then try the refresh again.


    Here's the thing i did:

    Dim count As Integer
    Dim nama() As String
    Dim j As Integer

    count = Selection.Rows.count 'counting number of rows with names in them
    ReDim nama(1 To count) 'specifying number of names to count above

    For j = 1 To count Step 1

    nama(j) = Range("sheet1!A2").Offset(j - 1, 0) 'Assigning names to variables "nama(j)" from column A of sheet 1

    ActiveWorkbook.Worksheets.Add
    With ActiveSheet.QueryTables.Add("TEXT;C:\Comics\" & nama(j) & ".csv" _
    , Destination:=Range("A1"))
    ...
    ...
    ...
    .TextFileTrailingMinusNumbers = True
    .Refresh BackgroundQuery:=False
    SO when I run it, it fails.. however, if I change the last line to

    With ActiveSheet.QueryTables.Add("TEXT;C:\Comics\Comic1.csv" _
    , Destination:=Range("A1"))
    instead of nama(j), it'll run fine... Except that it'll just open 100 new sheets filled with comic1's data.


    Any help is appreciated. THanks in advanced

  2. #2
    Registered User
    Join Date
    09-23-2004
    Posts
    2
    *bump* for now

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1