I am current using the code retrieved from Struggling to open most recent .xls in specified folder. File Not Found error. I would like to open several files when the active workbook is opened. Then, I would like to close all of the open files when the active workbook is closed. Can I loop the pathways for all of the documents to open? Please see the current code below:
Sub Auto_Open()
Dim FileSys As FileSystemObject
Dim objFile As File
Dim myFolder As Object
Dim strFilename As String
Dim dteFile As Date
Const myDir As String = "G:\S\Staffing\Attendance\July 2016"
Set FileSys = New FileSystemObject
Set myFolder = FileSys.GetFolder(myDir)
dteFile = DateSerial(1900, 1, 1)
For Each objFile In myFolder.Files
If objFile.DateLastModified > dteFile Then
dteFile = objFile.DateLastModified
strFilename = objFile.path
End If
Next objFile
Workbooks.Open strFilename
Set FileSys = Nothing
Set myFolder = Nothing
Windows("dashboard.xlsm").Activate
End Sub