How to open Multiple files through dates modified

kangero

New Member
Joined
Jun 3, 2019
Messages
2
Hello,

I am trying to figure out how to open multiple files with different names based on date modified. For example, I have 4 files and the names on them go 5Ab458, 5Dd5578,57C604P,548SKJV. There are multiple files in this folder as well so naming on each file is different so i need to open all specifically by date. So I would open 4 files for July 25. then close and open 4 files for July 26 e.t.c. How would I program something like this? is it possible to do this in vba or do I need to use python or something else and link it to excel VBA.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Here is one way.

Code:
Sub t()
Dim wb As Workbook, fPath As String, fName As String
fPath = ThisWorkbook.Path & "\"
fName = Dir(fPath & "*.xlsx")
    Do While fName <> ""
        If ThisWorkbook.Name <> fName Then
            Set fs = CreateObject("Scripting.FileSystemObject")
            Set f = fs.GetFile(fPath & fName)
            q = MsgBox("Date last modified is: " & f.DateLastModified & ".  Do you want to open this file?, vbYesNo, "OPTIONT TO OPEN")
                If q = vbYes Then
                    Set wb = Workbooks.Open(fPath & fName)
                    'other code here if needed
                    wb.Close False
                End If
        End If
        fName = Dir
    Loop
End Sub

Note the comment about additional code. That is your choice, but if you do not use code to edit your workbooks, then I suggest you delete the 'wb.Close False' line so you can manually do the edits and manually close the workbooks that were opened.
 
Upvote 0
sorry forgot to mention these files were pdf files and also wanted to know if fpath can be this "C:\Users\specia4\Downloads\UiAutomation"
 
Upvote 0
Modified per post #3

Code:
Sub t()
Dim wb As Workbook, fPath As String, fName As String
fPath = "C:\Users\specia4\Downloads\UiAutomation\"
fName = Dir(fPath & "*.pdf")
    Do While fName <> ""
        If ThisWorkbook.Name <> fName Then
            Set fs = CreateObject("Scripting.FileSystemObject")
            Set f = fs.GetFile(fPath & fName)
            q = MsgBox("Date last modified is: " & f.DateLastModified & ".  Do you want to open this file?", vbYesNo, "OPTIONT TO OPEN")
                If q = vbYes Then
                    Set wb = Workbooks.Open(fPath & fName)
                    'other code here if needed
                    wb.Close False
                End If
        End If
        fName = Dir
    Loop
End Sub
You might be better off using the GetOpenFilename method and selecting the files via a dialog box.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top