+ Reply to Thread
Results 1 to 2 of 2

Code for Opening File Based on Last Modified

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Code for Opening File Based on Last Modified

    I got this code off of this website and it seemed to be working great when there were only a few files in the folder. It is supposed to open the file in a folder with the most recent last modified date. It is now opening older workbooks for some reason. Also the code that tells it to only look at macro workbooks (Like "*xlsm) is making it skip past all files. But with this code disabled or not, something's amiss. Any ideas?

    Sub Open_File_Based_On_Last_Modified()
    
    Dim DateLastModified As Date
    Dim Filename As String
    Dim Filepath As Variant
    Dim Item As Variant
    Dim oFolder As Variant
    Dim NewestWkb As String
    Dim ThisWorkbookDate As Long
    
    
    Filepath = "M:\My Folder\Karen P\JP\Daily QA Report\Daily Review Archive"
    Filepath = IIf(Right(Filepath, 1) <> "\", Filepath & "\", Filepath)
    Set oShell = CreateObject("Shell.Application")
    Set oFolder = oShell.Namespace(Filepath)
    For Each Item In oFolder.Items
    If LCase(Item.Name) Like "*.xlsm" Then
    If oFolder.GetDetailsOf(Item, 3) > LastDateModified Then
    NewestWkb = Item.Name
    LastModified = oFolder.GetDetailsOf(Item, 3)
    End if
    End If
    Next Item
    Workbooks.Open Filepath & NewestWkb & ".xlsm"
    End Sub

  2. #2
    Forum Contributor
    Join Date
    09-25-2012
    Location
    Ventura, united States
    MS-Off Ver
    Excel 2010
    Posts
    346

    Re: Code for Opening File Based on Last Modified

    Bump no reply

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. open the newest excel file in a folder based on modified date
    By dulitul in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-17-2013, 12:52 PM
  2. [SOLVED] VBA code for xlsm file's Last Modified Date/Time
    By btmtdk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-03-2012, 12:38 AM
  3. Format to open file based on Date Modified stamp
    By cabinetguy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-21-2011, 02:22 PM
  4. Code to pick up the last modified file in a folder
    By mccrimmon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-19-2007, 08:57 AM
  5. How do I turn on the Last Modified option when opening a file?
    By WomensHealthUSA in forum Excel General
    Replies: 0
    Last Post: 06-08-2005, 11:05 AM

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