Home > OS >  Variable vertical number of pages to print as PDF in VBA Excel
Variable vertical number of pages to print as PDF in VBA Excel

Time:05-12

I have a worksheet that has a print area made up of two parts (see figure below).

enter image description here

The first, at the top, is fixed, and represents four print pages. Number four never changes. The second represents a column of pages that varies in quantity. In VBA's default print as PDF option, the entire indicated region is printed, both the fixed region, the variable region and the blank region. But I don't want the blank region. I just want the blue and green region. I'm currently running the code:

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
                        OpenAfterPublish:=True, _
                        filename:=fname, _
                        Quality:=xlQualityStandard, _
                        IncludeDocProperties:=True, _
                        IgnorePrintAreas:=False

Can anyone helps me?

CodePudding user response:

Thanks to Ricardo A I found the solution. I just select the desirable areas for printing through the code:

ActiveSheet.Range("B1:G35" & "," & "I1:K23" & "," & "O1:W33" & "," & "Y2:Y" & LastRow). _
                        ExportAsFixedFormat Type:=xlTypePDF, _
                        OpenAfterPublish:=True, _
                        filename:=fname, _
                        Quality:=xlQualityStandard, _
                        IncludeDocProperties:=True, _
                        IgnorePrintAreas:=False

  • Related