Sunday, June 13, 2010

How to Save Excel Range as Image using VBA

How to copy Excel Range as Image using VBA / How to export Excel Range as Image

The following code saves the Excel Range (A1:B2) as an image.

It uses the Export function of the Chart object (Refer :How to Save a Chart as Image using Excel VBA)
to save as Image

Sub Export_Range_Images()

' =========================================
' Code to save selected Excel Range as Image
' =========================================

Dim oRange As Range
Dim oCht As Chart
Dim oImg As Picture



Set oRange = Range("A1:B2")
Set oCht = Charts.Add


oRange.CopyPicture xlScreen, xlPicture


oCht.Paste

oCht.Export FileName:="C:\temp\SavedRange.jpg", Filtername:="JPG"

End Sub

5 comments:

  1. Cool! But how do I set page size and multiple pages from the same spreadsheet and without creating a new spreadsheet with the image?

    How can I cope a cell value as the file save name?

    ljs2905@gmail.com

    ReplyDelete
  2. How do you apply this to a button?

    ReplyDelete
  3. Doesn't work for me.

    Windows XP Excel 2003

    Err 1004, Method 'Export' of Object '_chart' failed.

    wordy1 AT bigpond.com

    ReplyDelete
  4. Call the code from button's click event. It should work

    ReplyDelete

StumbleUpon
Share on Facebook

Visual Basic for Applications (VBA) Forum (recent threads)

CodeKeep VBA Feed

Visual Studio Tools for Office Forum (recent threads)

Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.

Office Business Applications (OBA) Team Blog

MSDN Code Gallery Published Resources For Tag VSTO

microsoft.public.vsnet.vstools.office Google Group