Hey guys! I already have a code that can open a file in some folder. But i need it to open not only one folder, but two. I cant set (mydir) to open two folders, because i got an error! the code follows below:
Sub GetMostRecentFile()
Dim FileSys As FileSystemObject
Dim objFile As File
Dim myFolder
Dim strFilename As String
Dim dteFile As Date
'set path for files - change for your folder
Const myDir As String = "C:X"
'set up filesys objects
Set FileSys = New FileSystemObject
Set myFolder = FileSys.GetFolder(myDir)
'loop through each file and get date last modified. If largest date then store Filename
dteFile = DateSerial(1900, 1, 1)
For Each objFile In myFolder.Files
If objFile.DateLastModified > dteFile And FileSys.GetExtensionName(objFile) = "csv" Then
dteFile = objFile.DateLastModified
strFilename = objFile.Name
End If
Next objFile
Workbooks.Open myDir & "\" & strFilename
i need to open not only "C:X" but "C:Y" in the same code! Any ideas?
Sub GetMostRecentFile()
Dim FileSys As FileSystemObject
Dim objFile As File
Dim myFolder
Dim strFilename As String
Dim dteFile As Date
'set path for files - change for your folder
Const myDir As String = "C:X"
'set up filesys objects
Set FileSys = New FileSystemObject
Set myFolder = FileSys.GetFolder(myDir)
'loop through each file and get date last modified. If largest date then store Filename
dteFile = DateSerial(1900, 1, 1)
For Each objFile In myFolder.Files
If objFile.DateLastModified > dteFile And FileSys.GetExtensionName(objFile) = "csv" Then
dteFile = objFile.DateLastModified
strFilename = objFile.Name
End If
Next objFile
Workbooks.Open myDir & "\" & strFilename
i need to open not only "C:X" but "C:Y" in the same code! Any ideas?