Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Intro
- These code are to export a chart from Excel to .png and .pdf extensions.
- ## How to proceed
- go to **Tools > Macro > Visual Basic Editor**.
- 1. In the new window, select **Insert > Module** and copy some from codes available (SaveSelectedChartAsPDF or SaveSelectedChartAsImage) or in the blank page.
- 2. Then go to **File > Close > Return to Microsoft Excel**
- 3. Select a chart that you want to export
- 4. **Tools > Macro > Macros**, then select *SaveSelectedChartAsPDF* or *SaveSelectedChartAsImage* and press *Execute*.
- 5. Check the image at the folder (current directory).
- ### To export chart as PDF
- ```
- 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
- ```
- ### To export chart as PNG
- ```
- Sub SaveSelectedChartAsImage()
- ActiveChart.Export "figure.png"
- End Sub```
Add Comment
Please, Sign In to add comment