vba Print PDF not printing charts

shophoney

Active Member
Joined
Jun 16, 2014
Messages
286
Hi,

I've written vba code to print some ranges and include Charts. But the area is blank. The CHART properties and to allow printing.

I think the issue is in the code?

Public Sub Financia_Dashboard_PDF()

Dim strPath As String
Dim PDFfileName As String
Dim lastA As Long, _
lastF As Long, _
lastN As Long, _
lastR As Long

Dim PDFranges As Range

strTime = Format(Now(), "yyyy-mm-dd\_hhmm")

PDFfileName = "D:\Dropbox\Shared_Files\xxx.xxx\Reports\" & StrConv(ActiveSheet.Range("A2").Value & " - " & strTime & ".pdf", vbProperCase)

With ActiveSheet
lastA = .Cells(.Rows.Count, "A").End(xlUp).Row
lastF = .Cells(.Rows.Count, "F").End(xlUp).Row
lastN = .Cells(.Rows.Count, "N").End(xlUp).Row
lastR = .Cells(.Rows.Count, "R").End(xlUp).Row

Set PDFranges = .Range("A2:D" & lastA & _
",F2:L" & lastF & _
",N2:P" & lastN & _
",R2:Y" & lastR)

End With

PDFranges.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFfileName, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Going to need to guess here as you've not included any indication of where the charts are and what else is in thos ranges.

My guess is the charts are in ranges A:D, F:L, N:P or R:Y, below.

VBA Code:
With ActiveSheet
lastA = .Cells(.Rows.Count, "A").End(xlUp).Row
lastF = .Cells(.Rows.Count, "F").End(xlUp).Row
lastN = .Cells(.Rows.Count, "N").End(xlUp).Row
lastR = .Cells(.Rows.Count, "R").End(xlUp).Row

Set PDFranges = .Range("A2:D" & lastA & _
",F2:L" & lastF & _
",N2:P" & lastN & _
",R2:Y" & lastR)

End With

If it is the case that one or more of these ranges contains the chart and only the charts the end(xlUp) is going to evaluate the top row as the end, and ignore the chart as it's an chart object floating above the range. You can test this, place your cursor below one of the charts, press ctrl+up arrow.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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