tris070891
New Member
- Joined
- Sep 10, 2014
- Messages
- 12
I have successfully created a macro that opens the latest modified excel file in a folder. However I am unable to close the workbook after I open it. This is what the successful macro looks like:
So when workbook opens this is the code that I have used in an attempt to close it
This doesn't work... Can anyone help me out?
Cheers!
Dim strFolder As String
Dim strFile As String
Dim latestFile As String
Dim dtLast As Date
' assign variables
strFolder = "S:\Active Projects\8450 - Woolworths EDR Brand Tracker Research\8450 - Project Documents\8450 - Fieldwork\8450 - Sample\8450 - Project History\"
strFile = Dir(strFolder & "\*.*", vbNormal)
' loop through files to find latest modified date
Do While strFile <> ""
If FileDateTime(strFolder & strFile) > dtLast Then
dtLast = FileDateTime(strFolder & strFile)
latestFile = strFolder & strFile
End If
strFile = Dir
Loop
Workbooks.Open (latestFile)
So when workbook opens this is the code that I have used in an attempt to close it
Workbooks.Close (latestFile)
This doesn't work... Can anyone help me out?
Cheers!