1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| Sub Automatisation()
Dim ws As Worksheet
Dim pdfName As String
Dim savePath As String
Dim confirmation As VbMsgBoxResult
' Spécifiez le dossier d'enregistrement des fichiers PDF
' Il faut mettre le chemin correct ici
savePath = "C:\Chemin\Vers\Le\Dossier\PDFs\"
' Demande à l'utilisateur s'il souhaite imprimer les fichiers PDF
confirmation = MsgBox("Voulez-vous imprimer les fichiers PDF?", vbYesNo + vbQuestion, "Imprimer PDF")
' Boucle à travers chaque onglet
For Each ws In ThisWorkbook.Sheets
' Crée le nom du PDF basé sur le nom de l'onglet
pdfName = ws.Name & ".pdf"
' Ajuste la taille de l'onglet pour un format A4 en mode paysage
With ws.PageSetup
.PaperSize = xlPaperA4
.Orientation = xlLandscape
End With
' Exporte l'onglet en PDF
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=savePath & pdfName, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
' Si l'utilisateur a répondu Oui, imprime le fichier PDF
If confirmation = vbYes Then
' Imprime le fichier PDF
Shell "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe /t """ & savePath & pdfName & """"
End If
Next ws
End Sub |
Partager