Forum Discussion
Jonathan865
Sep 16, 2021Copper Contributor
Excel VBA Printing from a variable range
Hello, Im trying to create a VBa code that will print from a variable range. Currently in a sheet there are 50 pages (templates) that im printing. If there a way to print inly the pages that have...
HansVogelaar
Sep 16, 2021MVP
Try this:
Sub ExportPages()
Dim wsh As Worksheet
Dim n As Long
Dim i As Long
Set wsh = Worksheets("Certificate Template - AD")
n = wsh.PageSetup.Pages.Count
For i = 1 To n
wsh.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=wsh.Range("B" & 56 * (i - 1) + 1).Value, _
From:=i, To:=i
Next i
End Sub