Excel range save as image

ali zaib

Active Member
Joined
Nov 21, 2010
Messages
412
Kindly support to guide about can save excel specific cells as image to a folder .
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
.
Save as .JPG

Code:
Option Explicit


Sub Example1()
Dim i As Integer
Dim intCount As Integer
Dim objPic As Shape
Dim objChart As Chart


'copy the range as an image
Call Sheet1.Range("A1:E12").CopyPicture(xlScreen, xlPicture)


    'remove all previous shapes in sheet2
    intCount = Sheet2.Shapes.Count
        For i = 1 To intCount
            Sheet2.Shapes.Item(1).Delete
        Next i
    'create an empty chart in sheet2
    Sheet2.Shapes.AddChart
    'activate sheet2
    Sheet2.Activate
    'select the shape in sheet2
    Sheet2.Shapes.Item(1).Select
    Set objChart = ActiveChart
    'paste the range into the chart
    objChart.Paste
    'save the chart as a JPEG
    objChart.Export ("C:\Users\My\Desktop\TestImage.Jpeg")
    
End Sub



Save as .GIF

Code:
Option Explicit


Sub Save_Range_As_GIF()
    Dim MyChart As Chart
    Dim objPict As Object
    Dim RgCopy As Range
    
    Range("B2:G24").CopyPicture Appearance:=xlScreen, Format:=xlBitmap
    ActiveSheet.PasteSpecial Format:="Bitmap"
    Set objPict = Selection
        
    objPict.CopyPicture 1, 1
    Set MyChart = ActiveSheet.ChartObjects.Add(1, 1, objPict.Width + 10, objPict.Height + 10).Chart
    
    With MyChart
        .Paste
        .Export ThisWorkbook.Path & Application.PathSeparator & "Temp.gif"
        .Parent.Delete
    End With
    
    MsgBox ThisWorkbook.Path & Application.PathSeparator & "Temp.gif" & " is created !"
    
    objPict.Delete
    Set objPict = Nothing
End Sub
 
Upvote 0
Thanks for your support
Actually i want to save as image to a range instead of chart kindly support
 
Upvote 0
.
Here is another macro that save a specified range as a .JPG file to the same location as the workbook.

Code:
Option Explicit


Sub Export()


 Dim oWs As Worksheet
 Dim oRng As Range
 Dim oChrtO As ChartObject
 Dim lWidth As Long, lHeight As Long


 Set oWs = ActiveSheet
 Set oRng = oWs.Range("A1:H16")


 oRng.CopyPicture xlScreen, xlPicture
 lWidth = oRng.Width
 lHeight = oRng.Height


 Set oChrtO = oWs.ChartObjects.Add(Left:=0, Top:=0, Width:=lWidth, Height:=lHeight)


 oChrtO.Activate
 With oChrtO.Chart
  .Paste
  .Export Filename:="Case.jpg", Filtername:="JPG"
 End With


 oChrtO.Delete


End Sub

Run the macro then check the saved image properties. You will see that it is a .JPG image and not a chart.

Also, the previous two macros create and image, not a chart. Check the properties of the saved images.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top