VBA: Export excel range as image and save as file.


/ Published in: Visual Basic
Save to your folder(s)

PROBLEM:
How to save Excel range into image file. VBA macro in Excel 2007.

SOLUTION:
Create an empty chart, paste range image into chart area, and Export as image file.

Modify code to suite to your needs.


Copy this code and paste it in your HTML
  1. ''' Set Range you want to export to file
  2. Dim rgExp As Range: Set rgExp = Range("B5:H14")
  3. ''' Copy range as picture onto Clipboard
  4. rgExp.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
  5. ''' Create an empty chart with exact size of range copied
  6. With ActiveSheet.ChartObjects.Add(Left:=rgExp.Left, Top:=rgExp.Top, _
  7. Width:=rgExp.Width, Height:=rgExp.Height)
  8. .Name = "ChartVolumeMetricsDevEXPORT"
  9. .Activate
  10. End With
  11. ''' Paste into chart area, export to file, delete chart.
  12. ActiveChart.Paste
  13. ActiveSheet.ChartObjects("ChartVolumeMetricsDevEXPORT").Chart.Export "C:\testmeExportChart.jpg"
  14. ActiveSheet.ChartObjects("ChartVolumeMetricsDevEXPORT").Delete

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.