Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function ShellExecute Lib "shell32" Alias "ShellExecuteA" (ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#Else
Private Declare Function ShellExecute Lib "shell32" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
#End If
Private Const SW_HIDE As Long = 0&
Public Sub Print_PDFs2)
Dim table As ListObject
Dim i As Long, n As Long
Dim school As String
Dim bannerSheet As Worksheet
Set table = ActiveSheet.ListObjects(1)
Set bannerSheet = ThisWorkbook.Worksheets.Add(Before:=ThisWorkbook.Worksheets(1))
With table
school = ""
For i = 1 To .DataBodyRange.Rows.Count
If .DataBodyRange(i, 1).Value <> school Then
school = .DataBodyRange(i, 1).Value
With bannerSheet.Range("C25")
.Clear
.Value = school
.Font.Name = "Calibri"
.Font.Size = 72
.Font.Bold = True
End With
bannerSheet.PrintOut
End If
For n = 1 To .DataBodyRange(i, 3).Value
ShellExecute_Print .DataBodyRange(i, 2).Value
Next
Next
End With
Application.DisplayAlerts = False
bannerSheet.Delete
Application.DisplayAlerts = True
End Sub
Public Sub ShellExecute_Print(file As String, Optional printerName As String)
If printerName = "" Then
ShellExecute Application.hwnd, "PrintTo", file, vbNullString, 0&, SW_HIDE
Else
ShellExecute Application.hwnd, "PrintTo", file, Chr(34) & printerName & Chr(34), 0&, SW_HIDE
End If
End Sub