jjobrien03
New Member
- Joined
- Sep 2, 2014
- Messages
- 41
I am looking to open the most recent file in a certain directory, copy certain ranges from that file into specific ranges of another file (the workbook from which I am executing the code) then close out the workbook which I had previously opened. I have the code to open the most recent workbook, but I can't figure out how to copy from that workbook to the workbook from which I am running the code. Any help would be appreciated.
Summary:
Open most recent file
Copy information (from multiple sheets) from that file to other workbook (where I am executing code)
Close opened workbook
The code I have so far, which works perfectly is:
Summary:
Open most recent file
Copy information (from multiple sheets) from that file to other workbook (where I am executing code)
Close opened workbook
The code I have so far, which works perfectly is:
Code:
Option Explicit
Sub reportpackage()
Dim MyPath As String
Dim MyFile As String
Dim LatestFile As String
Dim LatestDate As Date
Dim LMD As Date
MyPath = "C:\Users\Me\Desktop\Report Packages"
If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
MyFile = Dir(MyPath & "*.xls", vbNormal)
If Len(MyFile) = 0 Then
MsgBox "No files were found...", vbExclamation
Exit Sub
End If
Do While Len(MyFile) > 0
LMD = FileDateTime(MyPath & MyFile)
If LMD > LatestDate Then
LatestFile = MyFile
LatestDate = LMD
End If
MyFile = Dir
Loop
Workbooks.Open MyPath & LatestFile
End Sub