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.
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!
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!