Hi All,
Struggling with some VBA to print multiple print ranges to one document ( 3 pages)
Code below is my attempt so far but I am not sure how to print an array for multiple ranges !
Any thoughts please?
I know the code needs cleaning up somewhat and would also appreciate some help there too.
Code
Sub PrintPDFPrint()
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strTime As String
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
On Error GoTo errHandler
Set wbA = ActiveWorkbook
Set wsA = ActiveSheet
strTime = Format(Now(), "dd mmm yyyy")
strPath = wbA.Path
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
.LeftMargin = Application.CentimetersToPoints(1.5)
.RightMargin = Application.CentimetersToPoints(1.5)
.TopMargin = Application.CentimetersToPoints(1.9)
.BottomMargin = Application.CentimetersToPoints(1.9)
.HeaderMargin = Application.CentimetersToPoints(0.9)
.FooterMargin = Application.CentimetersToPoints(0.9)
.PaperSize = xlPaperA4
.PrintQuality = 600
.Orientation = xlPortrait
.Zoom = False
.Draft = False
.FitToPagesWide = 1
.FitToPagesTall = 3
End With
PrntArea = Array("$D$1:$M$40", "$D$42:$M$67", "$D$69:$M$90")
ActiveSheet.PageSetup.PrintArea = PrntArea(i)
Worksheets("HRReviews").PageSetup.CenterHorizontally = True
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"
strName = Replace(wsA.Name, " ", "")
strName = Replace(strName, ".", " - ")
strFile = " - " & strTime & ".pdf"
strPathFile = strPath & strFile
myFile = Application.GetSaveAsFilename _
(InitialFileName:=Range("F6").Value & " - Progress " & Range("F4").Value & strFile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and FileName to save")
If myFile <> "False" Then
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
MsgBox "PDF file has been created: " _
& vbCrLf _
& myFile
End If
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler
End Sub
Display More