9398 shaares
13 liens privés
13 liens privés
Pour un répertoire /
Dim RepertoireExiste As Boolean
If Len(Dir(Repertoire, vbDirectory)) > 0 Then
RepertoireExiste = True
Else
RepertoireExiste = False
MsgBox "Le répertoire n'existe pas pour ce RUN." & vbLf & Repertoire, vbExclamation + vbOKOnly
Exit Function
End If
Ne pas oublier l'attribut vbDirectory
. C'est grâce à lui que la fonction Dir()
sait qu'on est sur un répertoire.
Pour un fichier :
Dim FichierExiste As Boolean
If Len(Dir(Repertoire & ModeleNomFichier)) > 0 Then
FichierExiste = True
End If
Alternatives, en utilisant la référence Microsoft Scripting Runtime
sous Excel
Dim FS As Scripting.FileSystemObject
Set FS = New Scripting.FileSystemObject
If Not FS.FolderExists(Repertoire) Then
MsgBox "Le répertoire n'existe pas" + vbCrLf + Repertoire, vbCritical, "Répertoire inexistant"
Exit Function
End If
Pour un fichier, utiliser FS.FileExists(Repertoire + "\" + Fichier)
.