+ Reply to Thread
Results 1 to 6 of 6

Import txt files but not being forced to select them from one location (path)

  1. #1
    Registered User
    Join Date
    02-08-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    52

    Import txt files but not being forced to select them from one location (path)

    Hi All,

    I need to import mulitple text files into one Excel 2007 worksheet which are delimited by '|'. However, rather than hardcoding the folder path where the .txt files are saved, I'd like the user to be able to select the folder and file from wherever they saved them. I don't want them to go through the import wizard though.

    Any thoughts?

    Thanks

    bob

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import txt files but not being forced to select them from one location (path)

    here's a snippet of code to set the import path via popup selection window, that folder will be stored as the variable fPath, then you can use that reference in the rest of your existing macro...which you didn't share, so I expect you'll adapt it.

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    02-08-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Import txt files but not being forced to select them from one location (path)

    Hi,

    Thanks but I haven't built a macro yet. I wanted the whole macro to import a text file into the current worksheet with a pop-up window to select the file as the files will be in different locations depending on the user.

    Thanks

    SB

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import txt files but not being forced to select them from one location (path)

    Since during the importation of a text file there are several decisions you have to make, turn on the macro recorder and record all the steps you currently go through to get a text file imported. Post the resulting code and we can adjust it together to add the snippet above.
    Last edited by JBeaucaire; 04-04-2011 at 06:03 PM.

  5. #5
    Registered User
    Join Date
    02-08-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Import txt files but not being forced to select them from one location (path)

    Hi,

    Thanks for your help! I did what you suggested and below is the code:
    Please Login or Register  to view this content.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import txt files but not being forced to select them from one location (path)

    Simple enough. Look carefully at your macro, my original snippet, then compare them to the version here, make sure the changes I made make sense to you so you can edit, adapte, reuse this technique in the future:

    Please Login or Register  to view this content.

+ 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