Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using VBA code, how to export Excel worksheets as image in Excel 2003?

Please suggest the better way of exporting range of data from excel worksheets as image either in .jpeg or .png or in .gif.

like image 240
Vishal I P Avatar asked Apr 22 '13 09:04

Vishal I P


People also ask

How do I save an Excel range as a JPEG?

In Excel 2007, click Home > Paste > As Picture > Copy as Picture, in the Copy Picture prompt box, select the options as follows and click OK. 5. Click Save button, and the selected cells range has been saved as the picture format in the specific folder.


1 Answers

do you want to try the below code I found on the internet somewhere many moons ago and used.

It uses the Export function of the Chart object along with the CopyPicture method of the Range object.

References:

  • MSDN - Export method as it applies to the Chart object. to save the clipboard as an Image
  • MSDN - CopyPicture method as it applies to the Range object to copy the range as a picture

    dim sSheetName as string
    dim oRangeToCopy as range
    Dim oCht As Chart
    
    sSheetName ="Sheet1" ' worksheet to work on
    set  oRangeToCopy =Range("B2:H8") ' range to be copied
    
    Worksheets(sSheetName).Range(oRangeToCopy).CopyPicture xlScreen, xlBitmap
    set oCht =charts.add
    
    with oCht
        .paste
        .Export FileName:="C:\SavedRange.jpg", Filtername:="JPG"
    end with
    
like image 119
Our Man in Bananas Avatar answered Oct 11 '22 16:10

Our Man in Bananas