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

Waimea

Active Member
Joined
Jun 30, 2018
Messages
465
Office Version
  1. 365
Platform
  1. Windows
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?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
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
 
Upvote 0
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
 
Upvote 0
Solution
Hi Yongle,

thank you for your reply!

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

Thank you!
 
Upvote 0
I have another question, how would I change the border to 0 and the background color of the chart to RGB(248, 248, 248) ?
 
Upvote 0

Forum statistics

Threads
1,214,874
Messages
6,122,036
Members
449,062
Latest member
mike575

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