+ Reply to Thread
Results 1 to 5 of 5

import all text files in folder

  1. #1
    Registered User
    Join Date
    06-15-2008
    Posts
    5

    import all text files in folder

    I am pretty new in VBA, so I hope I can get some help here.
    I have a folder of text files. Their names and number can change.
    I want to import them into excel, Either all into one workbook, different sheets, or each file into a separate .xls file.
    Another thing is that I need all columns to be imported as text.
    What I've achieved till now is a macro that imports one specific file, all columns as text.

    Please Login or Register  to view this content.
    How can I do this to all file in the folder?

    Thanks in advance for your help

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    This should point you in the right direction
    Uses a Do loop & Dir commands

    Please Login or Register  to view this content.
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Registered User
    Join Date
    06-15-2008
    Posts
    5
    Thanks a lot!
    With a few minor changes, this is exactly what I needed.
    I have a few more questions, and I'll be glad if you or anyone could help me with them.
    This process of importing data is done about once a day, and the text files might change (in number and name) throughout this time.
    What is the best way to do this anew each time? With a macro? Delete all sheets at beginning of macro? I'll appreciate your advice.
    The second issue is that I would like to name each sheet like the file name. How can I do this?

    Thanks again for your fine help.

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    You can delete all but 1 sheet from the book
    or
    You could create a new book eack time the macro is run

    Which method is best I don't know. I ususally recomend go with the method you feel comfortable with

    I do not know if there is or is not any problems that will be caused by continually adding and deleting sheets from the same book all the time


    You can name a sheet when its added or at a later time

    To name when added use
    Please Login or Register  to view this content.
    The following code names the sheet after it is added and also deletes al sheets except sheet(1) and is based on the code I 1st pasted

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-15-2008
    Posts
    5
    Thanks! That was excellent!

+ 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