How to animate shapes and export as picture(s)?

Waimea

Active Member
Joined
Jun 30, 2018
Messages
423
Hi,

I am using excel to color shapes in different colors based on values in a column.

I am trying to export the collection of shapes into a picture (which I would like to create an animated gif from).

1. How can I offset the data range so that collection of shapes get different colors based on column B,C,D etc.
I want the collection of shapes to first get data from column B, then column C etc.

2. How can I export the collection of shapes into a picture?
 

Some videos you may like

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Waimea

Active Member
Joined
Jun 30, 2018
Messages
423
VBA Code:
Public Sub SaveAsPicture_Example()
 
 ThisDocument.Pages(1).Shapes(1).SaveAsPicture "filename.jpg"
 
End Sub

I can't get this code to work?

I have one large shape and the large shape contains smaller shapes.

I want to export the large shape into a picture in C:\Reports\filename.gif
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,977
Office Version
  1. 365
Platform
  1. Windows
2. How can I export the collection of shapes into a picture?
Group the shapes and then use something like this which works for me
- amend to suit your own requirement
VBA Code:
Sub SaveJpg()
    Dim ws As Worksheet, chtObj As Object
    Set ws = ActiveSheet
       
'Select and copy group
    ws.Shapes.Range(Array("Group 5")).Select
    Selection.CopyPicture
'Create temporary chart
    Set chtObj = ws.ChartObjects.Add(1, 1, Selection.Width, Selection.Height)
'Paste the Group into chart
    chtObj.Select
    chtObj.Chart.Paste
'Export image
    chtObj.Chart.Export fileName:="C:\Test\testShape.jpg", Filtername:="JPEG"
'Tidy up
    chtObj.Delete
    Set chtObj = Nothing
End Sub
Original shapes in worksheet
ShapesCollection.jpg


Saved jpeg
testShape.jpg
 
Solution

Waimea

Active Member
Joined
Jun 30, 2018
Messages
423
Hi Yongle,

thank you for your reply!

Your code does what I want and I amended it to suit my needs.

Thank you!
 

Waimea

Active Member
Joined
Jun 30, 2018
Messages
423
I have another question, how would I change the border to 0 and the background color of the chart to RGB(248, 248, 248) ?
 

Watch MrExcel Video

Forum statistics

Threads
1,127,342
Messages
5,624,114
Members
416,012
Latest member
rockermom59

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
Top