Option Compare Text 'la casse est ignorée
Sub Imprimer() 'bouton Imprimer
If [D6] = "imprimante" Then Imprimante
If [D6] Like "un pdf*" Then PDF
If [D6] Like "*global*" Then PDF_Global
End Sub
Sub Imprimante()
Dim ville$, loisirs$, tablo, i&, n%
ville = [K5]: loisirs = [K6]
tablo = [J27].CurrentRegion.Resize(, 4) 'matrice, plus rapide
[C13:C16] = "" 'RAZ
For i = 2 To UBound(tablo)
If tablo(i, 3) = ville And tablo(i, 4) = loisirs Then
Range("C13") = tablo(i, 2)
Range("C14") = tablo(i, 1)
Range("C15") = ville
Range("C16") = loisirs
ActiveSheet.PageSetup.PrintArea = "$A$10:$D$17"
ActiveSheet.PrintPreview 'pour tester
'ActiveSheet.PrintOut 'pour imprimer
n = n + 1
Range("D8") = n
End If
Next
If n Then MsgBox n & " fiche" & IIf(n > 1, "s", "") & " imprimée" & IIf(n > 1, "s", ""), , "Imprimante"
End Sub
Sub PDF()
Dim chemin$, ville$, loisirs$, tablo, i&, n%
chemin = ThisWorkbook.Path & "\" 'dossier à adapter
ville = [K5]: loisirs = [K6]
tablo = [J27].CurrentRegion.Resize(, 4) 'matrice, plus rapide
Application.ScreenUpdating = False
[C13:C16] = "" 'RAZ
For i = 2 To UBound(tablo)
If tablo(i, 3) = ville And tablo(i, 4) = loisirs Then
Range("C13") = tablo(i, 2)
Range("C14") = tablo(i, 1)
Range("C15") = ville
Range("C16") = loisirs
ActiveSheet.PageSetup.PrintArea = "$A$10:$D$17"
ActiveSheet.ExportAsFixedFormat xlTypePDF, chemin & tablo(i, 1) & " " & tablo(i, 2) & " " & Format(Now, "yyyy-mm-dd hhmm")
n = n + 1
Range("D8") = n
End If
Next
Application.ScreenUpdating = True
If n Then MsgBox n & " fichier" & IIf(n > 1, "s", "") & " PDF créé" & IIf(n > 1, "s", ""), , "PDF"
End Sub
Sub PDF_Global()
Dim chemin$, ville$, loisirs$, tablo, i&, n%
chemin = ThisWorkbook.Path & "\" 'dossier à adapter
ville = [K5]: loisirs = [K6]
tablo = [J27].CurrentRegion.Resize(, 4) 'matrice, plus rapide
Application.ScreenUpdating = False
[C13:C16] = "" 'RAZ
[A10:D17].Copy
Workbooks.Add.Sheets(1).Paste 'documen auxiliaire
Application.CutCopyMode = 0
For i = 2 To UBound(tablo)
If tablo(i, 3) = ville And tablo(i, 4) = loisirs Then
If n Then Range("A1:D8").Copy Range("A1").Offset(n)
Range("C4").Offset(n) = tablo(i, 2)
Range("C5").Offset(n) = tablo(i, 1)
Range("C6").Offset(n) = ville
Range("C7").Offset(n) = loisirs
n = n + 9
End If
Next
ActiveSheet.ExportAsFixedFormat xlTypePDF, chemin & "PDF global " & Format(Now, "yyyy-mm-dd hhmm")
ActiveWorkbook.Close False
n = n / 9
Application.ScreenUpdating = True
If n Then MsgBox n & " fiche" & IIf(n > 1, "s", "") & " créée" & IIf(n > 1, "s", ""), , "PDF global"
End Sub