+ Reply to Thread
Results 1 to 6 of 6

Thread: Find newest file in a folder

  1. #1
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Find newest file in a folder

    Hi all,

    I am doing a project for work at the moment where by I have to manipulate a report compiled by an external program and do various bits and bobs to it. Trouble is, the other program creates a new version every time it runs the report (i.e filename.1.xls, and the next day filename.2.xls, and so on). Is there any way of searching the folder these files are in to find the newest file and select that one as the one to open and manipulate? There will be no files other than these in the folder.

    Thanks,
    David
    Last edited by duckboy1981; 10-30-2008 at 07:33 AM.

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  3. #3
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185
    Looks to be just what I am after. I will have a play when I get chance and let you know.

    Thanks

  4. #4
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639
    Thanks, let us know & mark the Thread solved when you have checked.
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  5. #5
    Valued Forum Contributor MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    888
    Hi, This is more or less what you've already got from "RoyUk"
    NB:- Change File Path to suit.
    Dim f As String, Directory As String
    Dim Fdate As Date
    Dim Temp As Date, nFile As String
    Directory = "C:\documents and settings\test\desktop\excel\"
        f = Dir(Directory)
    
    Do While f <> ""
    Fdate = FileDateTime(Directory & f)
      If Not f = ThisWorkbook.name Then
         If Fdate > Temp Then
           Temp = Fdate
           nFile = f
        End If
    End If
    
    f = Dir()
    Loop
    MsgBox nFile & " " & Temp
    Workbooks.Open (Directory & nFile)
    Regards Mick

  6. #6
    Forum Contributor
    Join Date
    09-03-2008
    Location
    Somerset, England
    MS-Off Ver
    XP, 2003, 2007 - depends on location
    Posts
    185

    Sorted!

    Thanks very much, works a treat!

+ 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.2.0