'vérifier l'existence du fichier Dim oFSO Set oFSO = CreateObject("Scripting.FileSystemObject") 'si le fichier existe if oFSO.FileExists("C:\Documents and Settings\toto\Bureau\import_12.xls") = true then 'on affiche une alerte if msgbox ("le fichier exite voulez vous continuer",vbyesno) = vbyes then kill "C:\Documents and Settings\toto\Bureau\import_12.xls" else 'le fichier n'existe pas tu fait ce que tu veut end if end if
'Déclaration des variables Dim oFSO Dim appExcel As Excel.Application 'Application Excel Dim wbExcel As Excel.Workbook 'Classeur Excel Dim wsExcel As Excel.Worksheet 'Feuille Excel Set oFSO = CreateObject("Scripting.FileSystemObject") 'si le fichier existe If oFSO.FileExists("C:\Documents and Settings\toto\Bureau\import_12.xls ") = True Then 'on affiche une alerte If MsgBox("le fichier existe voulez vous continuer", vbYesNo) = vbYes Then Set appExcel = CreateObject("Excel.Application") 'Ouverture d'un fichier Excel Set wbExcel = appExcel.Workbooks.Open("C:\Documents and Settings\toto\Bureau\import_12.xls ") 'wsExcel correspond à la première feuille du fichier Set wsExcel = wbExcel.Worksheets(1) 'fermeture et enregistrement 'Application.DisplayAlerts = False wbExcel.SaveAs " \\moi\ import_12_test.xls " wbExcel.SaveAs " C:\Documents and Settings\toto\Bureau\import_12.xls " wbExcel.Close " C:\Documents and Settings\toto\Bureau\import_12.xls " 'Désallocation mémoire Set wsExcel = Nothing Set wbExcel = Nothing Set appExcel = Nothing Else 'Désallocation mémoire Set wsExcel = Nothing Set wbExcel = Nothing Set appExcel = Nothing 'le fichier n'existe pas tu fait ce que tu veut End If End If
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question'Déclaration des variables Dim oFSO Dim appExcel As Excel.Application 'Application Excel Dim wbExcel As Excel.Workbook 'Classeur Excel Dim wsExcel As Excel.Worksheet 'Feuille Excel Set oFSO = CreateObject("Scripting.FileSystemObject") 'si le fichier existe If oFSO.FileExists("C:\Documents and Settings\toto\Bureau\import_12.xls") = True Then 'on affiche une alerte If MsgBox("le fichier exite voulez vous continuer", vbYesNo) = vbYes Then Set appExcel = CreateObject("Excel.Application") 'Ouverture d'un fichier Excel Set wbExcel = appExcel.Workbooks.Open("C:\Documents and Settings\toto\Bureau\import_12.xls") 'wsExcel correspond à la première feuille du fichier Set wsExcel = wbExcel.Worksheets(1) 'fermeture et enregistrement wbExcel.Application.DisplayAlerts = False wbExcel.SaveAs " \\moi\ import_12_test.xls" wbExcel.Close " C:\Documents and Settings\toto\Bureau\import_12.xls" 'Désallocation mémoire Set wsExcel = Nothing Set wbExcel = Nothing Set appExcel = Nothing MsgBox "Opération effectuée.", vbOKOnly + vbConfirmation, "Confirmation" 'Le fichier est inexistant Else End If Else MsgBox "Le fichier import_gmao n'existe pas sur votre bureau ou a été déplacé.", vbOKOnly + vbInformation, " Fichier d'import GMAO inexistant " 'Le fichier est inexistant End If