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
Cool! But how do I set page size and multiple pages from the same spreadsheet and without creating a new spreadsheet with the image?
ReplyDeleteHow can I cope a cell value as the file save name?
ljs2905@gmail.com
Thanks, it helped a lot!
ReplyDeleteHow do you apply this to a button?
ReplyDeleteI'm by no means an expert with VBA, but I would assume that you simply assign it as a macro, like you usually would. ('Sub' at the beginning determines the name).
DeleteDoesn't work for me.
ReplyDeleteWindows XP Excel 2003
Err 1004, Method 'Export' of Object '_chart' failed.
wordy1 AT bigpond.com
Call the code from button's click event. It should work
ReplyDeleteIS there a way to edit this to output PDF files?
ReplyDeletePublic Sub EXPORTER(ByRef fPath As String)
DeleteActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fPath, Quality:=xlQualityMedium, IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=False
End Sub
when i paste my data onto the chart it make a bar graph with the image of table superimposed on top. I just want the image of table. Any help?
ReplyDeleteI help me with this code before pasting picture
DeleteWith oCht
On Error Resume Next
.ChartArea.Delete
.Legend.Delete
On Error GoTo 0
End With
when i paste my range to the chart it creates bar graph with my table superimposed ontop. i want it to be just the image of the table.
ReplyDeleteHow do I specify which worksheet to be exported in your code??
ReplyDeleteReplace
DeleteSet oRange = Range("A1:B2")
with
Set oRange = Worksheets("Sheet1").Range("A1:B2")
Is there any way to save images which names are in excel sheet to a folder accordingly.
ReplyDelete@Chandan Kumar where are these Images available (as part of Excel or in a separate directory).
Delete@Chandan Kumar where are these Images available (as part of Excel or in a separate directory).
ReplyDelete