Printing a range to PDF plus one row using vba

Luis_B

New Member
Joined
Oct 13, 2021
Messages
38
Office Version
  1. 365
Platform
  1. Windows
Hey guys,

I'm trying to print to pdf the data on a sheet but I do not want the entire active sheet, just the data plus one extra row. With the code below I can catch the data from B1 to the last row but I would like to be able to add one more row to the PDF when printing it. The range changes every month so a set range would not work

I hope that makes sense

Thank you

With ActiveWorkbook

Worksheets("AEL").Range("b1", Range("i11").End(xlDown).End(xlToRight)).ExportAsFixedFormat Type:=xlTypePDF, Filename:="AEL", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

End With
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Where is the extra row you want to include in the PDF?

Maybe something like this:
VBA Code:
    Dim PDFrange As Range
    With ActiveWorkbook    
        Set PDFrange = .Worksheets("AEL").Range("B1", Range("I11").End(xlDown).End(xlToRight))
        Set PDFrange = PDFrange.Resize(PDFrange.Rows.Count + 1)
        PDFrange.ExportAsFixedFormat Type:=xlTypePDF, Filename:=.Path & "\AEL.pdf", _
            Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True    
    End With
 
Upvote 0
Where is the extra row you want to include in the PDF?

Maybe something like this:
VBA Code:
    Dim PDFrange As Range
    With ActiveWorkbook   
        Set PDFrange = .Worksheets("AEL").Range("B1", Range("I11").End(xlDown).End(xlToRight))
        Set PDFrange = PDFrange.Resize(PDFrange.Rows.Count + 1)
        PDFrange.ExportAsFixedFormat Type:=xlTypePDF, Filename:=.Path & "\AEL.pdf", _
            Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True   
    End With
Hi John, could you please help me with this code?

The code above that you helped me with only works properly if I filter some of the data that I have on a different Sheet (Sheet1). For example, sheet1(Where all the data is) has 15,000 rows and I only want the rows that contain AEL (about 150 rows) on column A to come over to sheet2 and then print to PDF. The code to bring the data over to sheet2 works great but only If I filter sheet1 by ABB. Do you have any idea why this could be?

I originally was using the below code to print the PDF (which I don't have to filter anything) but this code prints the entire active sheet and I would like it to just print a selection (which is the data that I'm bringing over to sheet2). I hope this make sense, I'm very new to VBA

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="AEL.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

Is there a way to fix the above code to just print the selection and not the entire active sheet?

Thank you,
 
Upvote 0
You've now added more information and complication that wasn't in your OP - filtering data, 2 sheets, code to copy between the sheets, filter by ABB/AEL, etc. - however your description isn't detailed or specific enough to answer your questions. Posting your code might help, along with the layout and sample data of the 2 sheets, posted using XL2BB.

Is there a way to fix the above code to just print the selection and not the entire active sheet?
Maybe:
VBA Code:
Selection.ExportAsFixedFormat Type:=xlTypePDF, Filename:="AEL.pdf", Quality:=xlQualityStandard, _
   IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,315
Members
449,081
Latest member
tanurai

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top