+ Reply to Thread
Results 1 to 2 of 2

Import most recent

Hybrid View

  1. #1
    Registered User
    Join Date
    04-03-2012
    Location
    Utah, USA
    MS-Off Ver
    Excel 2010
    Posts
    4

    Import most recent

    Hey everyone, I'm not skilled in vba, but I'm trying to create a macro that will automatically import data from a folder's most recently added file (.csv to be exact) into a spreadsheet. To give you a better idea of what I'm doing, I'm creating a flight log book for a pilot and he wants to be able to easily keep a running total of things like flight time and so on. He downloads a .csv file from his company every month so he has years worth of data that needs to be organized into a single ongoing spreadsheet, so I'm attempting to make it as easy for him as possible. Any help would be very appreciated. And please let me know if I can clarify anything, thanks!

  2. #2
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Import most recent

    This little macro should help you out, it will locate the oldest file in a folder and return the file name, in this case just to a msgbox, but im sure you could use that as you need.

    please let me know if you need any help

    Sub FindNewFile()
    Dim OldestFileDate As Date
    Dim OldestFileName, MyPath, CurrentFileName As String
    
    MyPath = "C:\TestFolder\"
    If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
    CurrentFileName = Dir(MyPath & "*.csv")
    
    Do
        If FileDateTime(MyPath & CurrentFileName) > OldestFileDate Then
            OldestFileName = MyPath & CurrentFileName
            OldestFileDate = FileDateTime(MyPath & CurrentFileName)
        End If
        CurrentFileName = Dir()
    Loop While CurrentFileName <> ""
    
    MsgBox (OldestFileName)
    End Sub
    If you liked my solution, please click on the Star -- to add to my reputation

    If your issue as been resolved, please clearly state so and mark the thread as [SOLVED] using the thread tools just above the first post.

+ 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