Guest User

Untitled

a guest
Jan 21st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. ## Intro
  2. These code are to export a chart from Excel to .png and .pdf extensions.
  3.  
  4. ## How to proceed
  5. go to **Tools > Macro > Visual Basic Editor**.
  6.  
  7. 1. In the new window, select **Insert > Module** and copy some from codes available (SaveSelectedChartAsPDF or SaveSelectedChartAsImage) or in the blank page.
  8. 2. Then go to **File > Close > Return to Microsoft Excel**
  9. 3. Select a chart that you want to export
  10. 4. **Tools > Macro > Macros**, then select *SaveSelectedChartAsPDF* or *SaveSelectedChartAsImage* and press *Execute*.
  11. 5. Check the image at the folder (current directory).
  12.  
  13. ### To export chart as PDF
  14. ```
  15. Sub SaveSelectedChartAsPDF()
  16. With ActiveChart.PageSetup
  17. .Orientation = xlLandscape
  18. .FitToPagesTall = 1
  19. .FitToPagesWide = 1
  20. .LeftMargin = 0
  21. .RightMargin = 0
  22. .BottomMargin = 0
  23. .TopMargin = 0
  24. End With
  25. ActiveChart.ExportAsFixedFormat xlTypePDF, ActiveWorkbook.Path + "\figure.pdf", xlQualityStandard, False, False
  26. End Sub
  27. ```
  28.  
  29. ### To export chart as PNG
  30. ```
  31. Sub SaveSelectedChartAsImage()
  32. ActiveChart.Export "figure.png"
  33. End Sub```
Add Comment
Please, Sign In to add comment