Option Explicit
Sub Test()
Dim Wbk As Workbook
Set Wbk = Classeur("C:\Users\vt\Documents\Auto\Script\THG_B_M")
End Sub
Function Classeur(ByVal ChNomFSsX As String) As Workbook
Dim P As Long, NomDoss As String, ArgDir As String, NomFSsX As String, NomFic As String
P = InStrRev(ChNomFSsX, "\")
NomDoss = Left$(ChNomFSsX, P - 1)
On Error Resume Next
ChDrive NomDoss: ChDir NomDoss
If Err Then MsgBox "Dossier """ & NomDoss & """ inaccessible.", _
vbCritical, "Classeur": Exit Function
NomFSsX = Mid$(ChNomFSsX, P + 1)
ArgDir = NomFSsX & "*.xl*"
NomFic = Dir(ArgDir)
If NomFic = "" Then MsgBox """" & ArgDir & """ introuvable sur" _
& vbLf & NomDoss, vbCritical, "Classeur": Exit Function
On Error Resume Next
Set Classeur = Workbooks(NomFic)
If Err = 0 Then Exit Function
Err.Clear
Set Classeur = Workbooks.Open(NomFic)
If Err Then MsgBox Err.Description, vbCritical, "Classeur"
End Function