G
GEORGIA
I am new to VBA.
I wanted to have a macro open a last modified workbook in the folder.
I saw the one code in the discussion group, his did not work so i changed it
little bit.
here's my code:
Sub OpenMost()
Dim strFolderName As String
strFolderName = "D:\My Documents"
On Error GoTo Err_Handler
Dim strFileName
With Application.FileSearch
.LookIn = strFolderName
.FileType = msoFileTypeExcelWorkbooks
.SearchSubFolders = True
If .Execute(msoSortByLastModified, msoSortOrderDescending) > 0 Then
strFileName = .FoundFiles(1)
Application.Workbooks.Open strFileName
End If
End With
Exit_Sub:
Exit Sub
Err_Handler:
Resume Exit_Sub
End Sub
instead of opening the last modified file, it is sorting by the file name
and opening the first one.
what is wrong with this code?
Thank You
I wanted to have a macro open a last modified workbook in the folder.
I saw the one code in the discussion group, his did not work so i changed it
little bit.
here's my code:
Sub OpenMost()
Dim strFolderName As String
strFolderName = "D:\My Documents"
On Error GoTo Err_Handler
Dim strFileName
With Application.FileSearch
.LookIn = strFolderName
.FileType = msoFileTypeExcelWorkbooks
.SearchSubFolders = True
If .Execute(msoSortByLastModified, msoSortOrderDescending) > 0 Then
strFileName = .FoundFiles(1)
Application.Workbooks.Open strFileName
End If
End With
Exit_Sub:
Exit Sub
Err_Handler:
Resume Exit_Sub
End Sub
instead of opening the last modified file, it is sorting by the file name
and opening the first one.
what is wrong with this code?
Thank You