X
xRoachx
I have two seperate questions regarding FileSearch & an Excel Instance. I'll
start with the latter. Thanks for the assistance.
I have a module that opens an Excel instance (objExcel) and closes it at the
end of the module by using objExcel.Quit & objExcel = Nothing. However, the
Excel instance is not closed correctly (still shows in the Task Manager) and
causes problems when the module is executed again. Each time I have to go to
Task Manager and manually close the instance.
The second question is regarding the following module. The module works
great the first time. However, if a second file is modified with a newer
date/time, the module is still displaying the previously last modified file
instead of the most recent modified file:
Function fLastModified(strFolder As String) As String
On Error GoTo Err_Handler
Dim strFileName As String
With Application.FileSearch
.NewSearch
.LookIn = strFolder
.FileType = msoFileTypeExcelWorkbooks
.SearchSubFolders = False
.Execute SortBy:=msoSortBySize
.LookIn = strFolder
.FileType = msoFileTypeExcelWorkbooks
If .Execute(msoSortByLastModified, msoSortOrderDescending) > 0 Then
strFileName = .FoundFiles(1)
'Application.Workbooks.Open strFileName
fLastModified = strFileName
End If
End With
Exit_Sub:
Exit Function
Err_Handler:
Resume Exit_Sub
End Function
start with the latter. Thanks for the assistance.
I have a module that opens an Excel instance (objExcel) and closes it at the
end of the module by using objExcel.Quit & objExcel = Nothing. However, the
Excel instance is not closed correctly (still shows in the Task Manager) and
causes problems when the module is executed again. Each time I have to go to
Task Manager and manually close the instance.
The second question is regarding the following module. The module works
great the first time. However, if a second file is modified with a newer
date/time, the module is still displaying the previously last modified file
instead of the most recent modified file:
Function fLastModified(strFolder As String) As String
On Error GoTo Err_Handler
Dim strFileName As String
With Application.FileSearch
.NewSearch
.LookIn = strFolder
.FileType = msoFileTypeExcelWorkbooks
.SearchSubFolders = False
.Execute SortBy:=msoSortBySize
.LookIn = strFolder
.FileType = msoFileTypeExcelWorkbooks
If .Execute(msoSortByLastModified, msoSortOrderDescending) > 0 Then
strFileName = .FoundFiles(1)
'Application.Workbooks.Open strFileName
fLastModified = strFileName
End If
End With
Exit_Sub:
Exit Function
Err_Handler:
Resume Exit_Sub
End Function