PDF registration with name incrementing

FlorianR -  
 ABD -
```vba
Sub PlanningSalle_SAVE()

LaDate1 = Format(Range("I8"), "dd" & "." & "mm" & "." & "yyyy")
LaDate2 = Format(Range("P8"), "dd" & "." & "mm" & "." & "yyyy")
I = 1
NomFichier = ("Planning Salle du " & LaDate1 & " au " & LaDate2 & "_V")

Dim Fichier As String

Fichier = Dir("C:\GestionResto\Planning Salle\" & NomFichier & I & ".pdf")

If Fichier <> "" Then

If MsgBox("Le fichier '" & Fichier & "' existe, voulez-vous créer une nouvelle version?", vbYesNo, "Attention") = vbYes Then
Do While Fichier <> ""
I = I + 1
Fichier = Dir("C:\GestionResto\Planning Salle\" & NomFichier & I & ".pdf")
Loop
Else
Exit Sub
End If
End If

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\GestionResto\Planning Salle\" & NomFichier & I & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
From:=1, To:=1, OpenAfterPublish:=True

End Sub
```

2 answers

via55 Posted messages 14388 Registration date   Status Member Last intervention   2 755
 
Hello Florian

Try replacing the end of your macro with this
chemin="C:\GestionResto\Planning Salle\" Fichier = Dir(chemin & NomFichier & "*" & ".pdf") n = 0 Do While Fichier <> "" n = n + 1 Fichier = Dir Loop If n > 0 Then If MsgBox("The file '" & NomFichier & n & "' exists, do you want to create a new version?", vbYesNo, "Warning") = vbNo Then Exit Sub End If ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ chemin & NomFichier & n+1 & ".pdf", Quality:= _ xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _ From:=1, To:=1, OpenAfterPublish:=True 

Cdmnt
Via

--
"Imagination is more important than knowledge."    A. Einstein
2
ABD
 
Thank you infinitely for this code.
0
FlorianR
 
Thank you very much, Via55! Exactly what I needed!
Thanks again :)
0