These code are to export a chart from Excel to .png and .pdf extensions.
go to Tools > Macro > Visual Basic Editor.
- In the new window, select Insert > Module and copy some from codes available (SaveSelectedChartAsPDF or SaveSelectedChartAsImage) or in the blank page.
- Then go to File > Close > Return to Microsoft Excel
- Select a chart that you want to export
- Tools > Macro > Macros, then select SaveSelectedChartAsPDF or SaveSelectedChartAsImage and press Execute.
- Check the image at the folder (current directory).
Sub SaveSelectedChartAsPDF()
With ActiveChart.PageSetup
.Orientation = xlLandscape
.FitToPagesTall = 1
.FitToPagesWide = 1
.LeftMargin = 0
.RightMargin = 0
.BottomMargin = 0
.TopMargin = 0
End With
ActiveChart.ExportAsFixedFormat xlTypePDF, ActiveWorkbook.Path + "\figure.pdf", xlQualityStandard, False, False
End Sub
Sub SaveSelectedChartAsImage()
ActiveChart.Export "figure.png"
End Sub```