+ Reply to Thread
Results 1 to 10 of 10

Open File With Latest Date

Hybrid View

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

    Re: Open File With Latest Date

    Something like this:
    Sub GetEmployeeCount()
    Dim sOpenLastReport As String, Cnt As Long, wb As Workbook
    
    Application.ScreenUpdating = False
    
    Do
        sOpenLastReport = "H:\Desktop\BA.com Daily Production Reports\" & _
                          Format(Date - Cnt, "MM-YY") & "\BA.com_ProductionReport_" & _
                          Format(Date - Cnt, "MM-DD-YY") & ".xlsm"
        
        If Len(Dir(sOpenLastReport)) > 0 Then Exit Do
        Cnt = Cnt + 1
        If Cnt Mod 10 = 0 Then
            If MsgBox("We've checked " & Cnt & " dates and not found a file, keep going backwards?", vbYesNo, "CONTINUE") = vbNo Then Exit Sub
        End If
    Loop
        
    Set wb = Workbooks.Open(sOpenLastReport)
    
    wb.Sheets("EmployeeCount").Range ("B4:Z17").Copy
    ThisWorkbook.Sheets("EmployeeCount").Range("C4").PasteSpecial xlPasteValues
    
    wb.Sheets("EmployeeCount").Range("B35:Z35").Copy
    ThisWorkbook.Sheets("EmployeeCount").Range("C35").PasteSpecial xlPasteValues
    
    wb.Close False
    Application.ScreenUpdating = True
    
    Exit Sub
    Last edited by JBeaucaire; 06-09-2015 at 04:45 PM. Reason: Fixed some typos
    _________________
    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!)

  2. #2
    Forum Contributor
    Join Date
    11-12-2014
    Location
    Boston, MA
    MS-Off Ver
    Office 2010
    Posts
    172

    Re: Open File With Latest Date

    Thanks. How is your Cnt variable working in this?

+ 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. [SOLVED] Automatically open the latest date modified excel file in a folder
    By arleutwyler in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-17-2014, 01:35 PM
  2. Replies: 9
    Last Post: 11-28-2013, 05:20 PM
  3. Open the 2nd latest file in a folder?
    By guydixon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-27-2013, 01:37 PM
  4. Open the latest file to copy and paste data in another file
    By mmf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-07-2008, 10:41 AM
  5. macro to open latest file
    By tsgol in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-25-2005, 08:05 PM

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