group of objects saved as png

smak

New Member
Joined
Mar 18, 2022
Messages
33
Office Version
  1. 2010
Platform
  1. Windows
I have objects that I have grouped. I want to save these grouped items as a png so it can be used later. .

I also pasted a copy of what the image would look partially like when it is saved.

when I have gotten charts to do this properly I used the code:
VBA Code:
    ActiveSheet.ChartObjects("Chart 2").Activate
    ActiveChart.Export "O:\OPHS\DE\Stephanie\c19 report\temp saved documents\images of charts\Cumulative Line Charts.png"

my grouped objects are referenced in the code below
VBA Code:
    ActiveSheet.Shapes.Range(Array("map")).Select
Picture1.png
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Basically the same as your charts code - copy the grouped shape to a temporary chart and save that.
VBA Code:
Public Sub Save_Shapes_Group_As_Image()

    Dim shp As Shape
    
    Set shp = ActiveSheet.Shapes("map")    
    Save_Object_As_Picture shp, ThisWorkbook.Path & "\map.png", "png"
    
End Sub


Private Sub Save_Object_As_Picture(saveObject As Object, imageFileName As String, imageType As String)

    'Save a picture of an object as a JPEG/PNG/GIF/SVG file
    
    'Arguments
    'saveObject     - any object in the CopyPicture method's 'Applies To' list, for example a Range or Shape
    'imageFileName  - the .jpg/.jpeg/.png/.gif/.svg file name (including folder path if required) the picture will be saved as
    'imageType      - the image type: jpeg, png, gif or svg
    
    Dim temporaryChart As ChartObject
     
    Application.ScreenUpdating = False
    
    saveObject.CopyPicture xlScreen, xlPicture
    
    Set temporaryChart = ActiveSheet.ChartObjects.Add(0, 0, saveObject.Width, saveObject.Height)
    With temporaryChart
        .Activate                               'Required, otherwise image is blank
        .Border.LineStyle = xlLineStyleNone     'No border
        .Chart.Paste
        .Chart.Export imageFileName, imageType
        .Delete
    End With
    
    Application.ScreenUpdating = True
    
    Set temporaryChart = Nothing
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,116
Messages
6,128,933
Members
449,480
Latest member
yesitisasport

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