Vérifier la présence d'un fichier sous Excel

Résolu
Utilisateur anonyme - 15 sept. 2004 à 16:57
 Utilisateur anonyme - 15 sept. 2004 à 17:55
Bonjour,

Je souhaite créer l'enregistrement d'un classeur Excel dans un répertoire bien défini.
Mais avant je souhaiterais savoir si un fichier portant le même nom existe...pour ne pas l'écraser.

Je ne sais pas si j'ai bien été clair...

Path = ActiveWorkbook.Path

Sheets("Maquette").Select
Sheets("Maquette").Copy
ActiveWorkbook.SaveAs Filename:=Path & "\toto.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
Message = MsgBox("Le fichier à été enregistré sous le nom suivant" & Chr(13) & Path & "toto.xls",vbinformation)

Enjoy and have fun !

2 réponses

jrivet Messages postés 7392 Date d'inscription mercredi 23 avril 2003 Statut Membre Dernière intervention 6 avril 2012 60
15 sept. 2004 à 17:14
salut,

ajoute la reference Windows Script Host Object Model.

Tu pourra utiliser le FileSystemObject comme suit:

Dim fs as new filesystemobject

Sheets("Maquette").Select
Sheets("Maquette").Copy

if fs.fileexists(Path & "\toto.xls") then
msgbox "le fichier existe deja"
else

ActiveWorkbook.SaveAs Filename:=Path & "\toto.xls", FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
Message = MsgBox("Le fichier à été enregistré sous le nom suivant" & Chr(13) & Path & "toto.xls",vbinformation)
end if

@+
-------------------------------------------------
Essai ca sinon on trouvera autre chose
-------------------------------------------------

:big)
3
Utilisateur anonyme
15 sept. 2004 à 17:55
Merci beaucoup !!!
Ca marche nikel !

A+

Enjoy and have fun !
0
Rejoignez-nous