Message avant d’effacer le fichier

Bonjour,

Avec cette macro

Sub Copyjpg()

Set Source = Range("AA101:AI110")

Source.CopyPicture xlScreen, xlPicture

Set gr = Sheets(2).ChartObjects.Add(0, 0, Source.Width, Source.Height)

nom = Range("AP101")

Workbooks.Add

With ActiveSheet.ChartObjects.Add(0, 0, Selection.Width, _

Selection.Height).Chart

.ChartArea.Border.LineStyle = 0

gr.Chart.Paste

gr.Chart.Export ThisWorkbook.Path & "\ticket\" & nom & " .jpg", "JPG"

End With

ActiveWorkbook.Close False

gr.Delete

End Sub

Je peux faire une sauvegarde en JPG

Le souci que je rencontre c’est que si le nom du fichier existe il va l’écraser sans me dire que le nom du fichier existe.

Il y aurait-il une personne pour me dire comment faire apparaitre un message qui me demanderait si je veux effacer le fichier ?

Avec une commande IF, cela doit bien être possible ?

Merci pour votre aide.

Bonjour realiste,

Tu peux tester l'existence du fichier au préalable et sortir de la macro le cas échéant :

Sub Copyjpg()
Set Source = Range("AA101:AI110")
Source.CopyPicture xlScreen, xlPicture
Set gr = Sheets(2).ChartObjects.Add(0, 0, Source.Width, Source.Height)
nom = Range("AP101")

jpgExist = Dir(ThisWorkbook.Path & "\ticket\" & nom & " .jpg")
If jpgExist <> "" Then
    rep = MsgBox("Le fichier existe déjà, voulez-vous le remplacer ?", vbYesNo)
    If rep = vbNo Then Exit Sub
End If

Workbooks.Add
With ActiveSheet.ChartObjects.Add(0, 0, Selection.Width, _
Selection.Height).Chart
.ChartArea.Border.LineStyle = 0
gr.Chart.Paste
gr.Chart.Export ThisWorkbook.Path & "\ticket\" & nom & " .jpg", "JPG"
End With
ActiveWorkbook.Close False
gr.Delete

End Sub

Génial c'est exactement ce que je voulais

Merci beaucoup de ton aide

Rechercher des sujets similaires à "message effacer fichier"