+ Reply to Thread
Results 1 to 5 of 5

Trying to import filename based on cell contents

  1. #1
    Registered User
    Join Date
    06-09-2006
    Posts
    8

    Question Trying to import filename based on cell contents

    Hi,

    I'm trying to import a TAB delimited text file into Excel. I've recorded a macro which has given me this (in part);

    Please Login or Register  to view this content.
    What I want to do is get the Macro to import a file based on the contents of cell B2 in a worksheet called 'Summary'. In my test case, I have a file called 'TEST-NAME' ready to import, and I have entered 'TEST-NAME' as text into the cell B2.

    The idea eventually is to allow for us to export data from our database using our unique codes as file names (all saved in the same place), then entering those unique codes into a particular cell ('B2' for this example) for import by a good old fashioned button press. I'd obviously need to trap errors based on spelling the file name incorrectly in cell 'B2' also.

    Now I'm stuck and need some help, and I have googled around all over the place to no real avail, although I do keep coming across .getOpenFileName but that doesn't look like what I'm after. I had tried something like this;

    Please Login or Register  to view this content.
    No joy there, but I have realised I was not referencing the correct worksheet and it wouldn't have worked anyway...I'm not sure how to reference the correct worksheet 'Summary' within the code above.

    Any help much appreciated. Hopefully it's clear, I do tend to ramble...
    Last edited by JesusOnEez; 06-28-2013 at 09:43 AM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Trying to import filename based on cell contents

    1) Attach please a sample file with code
    2) where is the text file ? in which folder ?
    If solved remember to mark Thread as solved

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Trying to import filename based on cell contents

    Try changing this;

    Please Login or Register  to view this content.
    To this:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-09-2006
    Posts
    8

    Re: Trying to import filename based on cell contents

    Brilliant, that works a treat. Now to error trap it for if someone enters an incorrect file name.

    Thanks again!

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Trying to import filename based on cell contents

    You're welcome. Glad to help out, and thanks for the feedback.

+ 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