PDF registration with name incrementing
FlorianR
-
ABD -
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
```
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
Hello Florian
Try replacing the end of your macro with this
Cdmnt
Via
--
"Imagination is more important than knowledge." A. Einstein
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
ABD
Thank you infinitely for this code.