Selecting Current Chart and Saving As PDF

Dagless

New Member
Joined
Jun 21, 2011
Messages
1
Hi all, I have been working on a series of visual basic projects that so far have been going well, but I have now hit a wall in my visual basic skills. :mad:

I'm trying to create a macro that will select a chart and save it as a pdf.

I think I'm pretty close and can create a macro that selects all charts in the current workbook and saves them as PDF to a specific location. I just can't figure out how to select ONLY the current chart and Save As PDF.

I can also configure the code to select one chart as long as the name of the Chart Object is known, but I need it to work regardless of whether the Chart Object name is known or not.

Any help would be amazing!

Here's my current code:

Sub SaveAsChart()
' Keyboard Shortcut: Ctrl+Shift+X


Dim ch As Chart
Dim filePath As String

ActiveWorkbook.RefreshAll
Application.DisplayAlerts = False

filePath = ActiveWorkbook.Path & "\PublicationPDFs\"
If Dir(filePath, vbDirectory) = "" Then MkDir filePath

For Each ch In ActiveWorkbook.Charts
ch.Select

ch.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
filePath & ActiveSheet.Name & ".pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False

Next ch

Application.StatusBar = "Ready"
Application.DisplayAlerts = True

End Sub




Thank you!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,224,603
Messages
6,179,854
Members
452,948
Latest member
UsmanAli786

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