+ Reply to Thread
Results 1 to 13 of 13

importing the newest file in a folder as text

  1. #1
    Registered User
    Join Date
    10-24-2010
    Location
    Melbourne, Aust
    MS-Off Ver
    Excel 2007
    Posts
    19

    importing the newest file in a folder as text

    Hi,

    I need to import a csv file into excel as text. As this is the only way I can retain all the info in all the cells, ie opening it directly in excel results in missing data, dont ask me why.. I download this file daily. I'd like to design a macro that would perform this function for me, ie import the newest file in my downloads folder as a text file. Following that i have another macro I run on the data.

    Thanks in advance!

    HW

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: importing the newest file in a folder as text

    Hi hotwheels

    Leith has code which you can modify form xlms to csv

    http://www.excelforum.com/excel-prog...-a-folder.html
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    10-24-2010
    Location
    Melbourne, Aust
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: importing the newest file in a folder as text

    Thanks for that link.

    What I am looking for is to import the latest file as text, rather than open it directly. I could probably use some of that code to find the most recent file, however i'm no expert in reading VBA code. Your help appreciated!

    HW

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: importing the newest file in a folder as text

    hi hotwheels
    sound like the csv file is a xls file with csv extension
    Has the csv file been save correctly?

  5. #5
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: importing the newest file in a folder as text

    Your post does not comply with Rule 7 of our Forum RULES. Please do not ignore Moderators' or Administrators' requests - note that this includes requests by senior members as well, if you are unclear about their request or instruction then send a private message to them asking for help. Do not post a reply to a thread where a moderator has requested an action that has not been complied with e.g Title change or Code tags...etc

    please address Roys request in your previous thread

  6. #6
    Registered User
    Join Date
    10-24-2010
    Location
    Melbourne, Aust
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: importing the newest file in a folder as text

    Thanks for the previous messages on this thread. this thread is now unblocked so any furhter help would be appreciated.

    Thanks,

    HW

  7. #7
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: importing the newest file in a folder as text

    hi hotwheels

    your can change the directory and sheet # to suit

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-24-2010
    Location
    Melbourne, Aust
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: importing the newest file in a folder as text

    Pike,

    Your code does open the latest file in the folder. Due to the characteristics of the file that I am opening however I lose data when I do it this way. In order to not lose data I use the Get External Data>From Text commands.

    I probably wasn't clear enough in my first post. Does this make it clearer? Principally I'm looking for a macro to retrieve data from the latest file in a folder using the Get External Data command.

    Thanks

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

    Re: importing the newest file in a folder as text

    You can see from Pike's code how he gets the filename to open. Then, his line of code shows he is opening the found filename with this:

    Please Login or Register  to view this content.

    So you should be able to take that same reference:
    Please Login or Register  to view this content.
    And use that in your GetData code. Give it a try. Merge your method of file extraction with his method of finding the filename.
    _________________
    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!)

  10. #10
    Registered User
    Join Date
    10-24-2010
    Location
    Melbourne, Aust
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: importing the newest file in a folder as text

    Thanks JBeau for the encouragement.

    This is the recording of the steps I use to get the data I want:

    Please Login or Register  to view this content.
    I'm a little unsure how to join this code to that supplied by Pike. I'm not particularly good at reading code but I guess the key is in the first couple of lines.

    I think I'd start the code with the first part of Pikes macro:
    Please Login or Register  to view this content.
    But where would I insert:

    Please Login or Register  to view this content.
    ?

    Yep, I'm still beginning at this.

    HW

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

    Re: importing the newest file in a folder as text

    Like so:
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    10-24-2010
    Location
    Melbourne, Aust
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: importing the newest file in a folder as text

    Great, thanks for this. It works a dream. I just updated the date to 2011.

    Will get this thread marked as solved.

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

    Re: importing the newest file in a folder as text

    Actually the line of code I accidentally left in:
    Please Login or Register  to view this content.
    ....can be removed. That was for testing on my system.
    Last edited by JBeaucaire; 03-06-2011 at 09:18 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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