Public NoPrint As Boolean
Private Sub Print_PDF()
NoPrint = True
Application.ScreenUpdating = False
' Vérification nom patient
If Sheets("Etude").Range("D22") = "Nom(s) et Prénom(s)" Then
MsgBox "Vous devez préciser le nom du patient!", vbCritical, "Analyses"
Exit Sub
End If
' ===============================
'Choix des feuilles à exporter
' ===============================
Dim Choix As String
Dim TabFeuilles() As String
Dim i As Integer
Dim Sh As Worksheet
Choix = InputBox("Entrez les noms des feuilles à exporter (séparés par des virgules) :" & vbCrLf & _
"Exemple : Feuil1,Feuil2,Feuil3")
If Choix = "" Then Exit Sub
TabFeuilles = Split(Choix, ",")
' Nettoyage des noms
For i = LBound(TabFeuilles) To UBound(TabFeuilles)
TabFeuilles(i) = Trim(TabFeuilles(i))
Next i
' Vérification existence feuilles
On Error GoTo ErreurFeuille
Sheets(TabFeuilles).Select
On Error GoTo 0
' ===============================
'Paramétrage impression
' ===============================
For Each Sh In ActiveWindow.SelectedSheets
With Sh.PageSetup
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.LeftMargin = Application.InchesToPoints(0.1)
.RightMargin = Application.InchesToPoints(0.1)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(0.1)
.Orientation = xlLandscape
End With
Next Sh
' ===============================
'Nom du fichier
' ===============================
Dim NFichier As String
NFichier = Sheets(TabFeuilles(0)).Range("D20") & "-" & _
Sheets(TabFeuilles(0)).Range("D22") & "-" & _
Format(Date, "dd-mm-yyyy")
' ===============================
'Export PDF
' ===============================
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ThisWorkbook.Path & "\" & NFichier, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=True
' Retour sur première feuille
Sheets(TabFeuilles(0)).Select
MsgBox "Le PDF a été enregistré !" & vbCrLf & vbCrLf & _
"Ici ==> " & ThisWorkbook.Path & vbCrLf & vbCrLf & _
"Sous le nom : " & NFichier & ".pdf", 64, "Analyses"
Application.ScreenUpdating = True
NoPrint = False
Exit Sub
' ===============================
' Gestion erreur
' ===============================
ErreurFeuille:
MsgBox "Une ou plusieurs feuilles n'existent pas !" & vbCrLf & _
"Vérifiez les noms saisis.", vbCritical
Application.ScreenUpdating = True
NoPrint = False
End Sub