troubleshooting Question

VBA Doubt

Avatar of VBAlearner2010
VBAlearner2010Flag for France asked on
Microsoft AccessMicrosoft Excel
11 Comments2 Solutions329 ViewsLast Modified:
How to make the following code work in Office 2010. Please edit the code with the suitable replacement for Application.Filesearch
Function LastFileSaved(sFileDir As String, DebutNomFichier As String, Optional sType As String = "*.*") As String

Dim fs
Set fs = Application.FileSearch
With fs
    .LookIn = sFileDir
    .Filename = DebutNomFichier
    
    If .Execute(SortBy:=msoSortByLastModified, _
        SortOrder:=msoSortOrderDescending) > 0 Then
        LastFileSaved = .FoundFiles(1)
    Else
        MsgBox "There were no files found in:" & vbLf & _
        sFileDir & vbLf & _
        "Type: " & sType
      LastFileSaved = vbNullString
    End If
End With

End Function


Function FileExist(Chemin, NomFichier) As Boolean
    
    ' Ne marche plus avec Excel 2007
    Set fs = Application.FileSearch
    With fs
        Resultat = False
        .LookIn = Chemin
        .Filename = NomFichier
        If .Execute > 0 Then FileExist = True Else FileExist = False
    End With
    
End Function
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros