Sub test()
Dim Chemin1 As String
Dim Chemin2 As String
Chemin1 = "E:\www\test\"
Chemin2 = "E:\www\test1\"
If NbFichiers(Chemin1) = 0 And NbFichiers(Chemin2) = 0 Then
MsgBox "Il n'y a ni facture ni devis établi pour le moment !", vbInformation, "Attention"
Else
MsgBox "il y a au moins une facture ou un devis"
End If
End Sub
Private Function NbFichiers(Dossier As String, Optional Extension As String = "*.*") As Double
'adapté de Ken Puls (www.excelguru.ca)
Dim objFiles As Object
Dim objFile As Object
'Set Error Handling
On Error GoTo SorsSorsSors
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFiles = objFso.GetFolder(Dossier).Files
If Extension = "*.*" Then
NbFichiers = objFiles.Count
Else
For Each objFile In objFiles
If UCase(Right(objFile.Path, (Len(objFile.Path) - InStrRev(objFile.Path, ".")))) = UCase(Extension) Then
NbFichiers = NbFichiers + 1
End If
Next objFile
End If
SorsSorsSors:
On Error Resume Next
Set objFile = Nothing
Set objFiles = Nothing
Set objFso = Nothing
On Error GoTo 0
End Function