Copy Embedded Charts as Shapes with VBA

Andy Pope recently posted a nice bit of code in response to a question posted in the Microsoft Excel Charting Discussion Group. The question asked how to copy a chart as a shape without using a selection event. I've struggled with this same question. Specifically, how do you to copy charts as shapes across different sheets without selecting the destination sheet. Andy's example does the trick:

Sub CopyChartsAsShapes()

    Application.ScreenUpdating = False

    Dim Cht As Chart
    Dim Rng As Range

    Set Cht = Sheets("MC").ChartObjects("Cht1").Chart

    For Each Rng In Sheets("Dash").Range("F4:F11")

        Cht.CopyPicture
        With Rng.Parent
            .Paste
            With .Shapes(.Shapes.Count)
                .LockAspectRatio = msoFalse
                .Left = Rng.Left
                .Top = Rng.Top
                .Width = Rng.Width
                .Height = Rng.Height
            End With
        End With

    Next Rng

    Cht.Deselect
    
    Application.ScreenUpdating = True

End Sub

In the example, the procedure copies a chart that resides on the sheet called "MC" to each cell within the range F4:F11 on the sheet called "Dash". The poster had named the chart "Cht1", which can easily be done by activating, or clicking on the embedded chart and then running the macro below:

Sub NameChart()
    ActiveChart.Parent.Name = "Cht1"
End Sub
Posted on January 07, 2009 | Filed under: Charts | Comments (0) | Permalink
Page 1 of 1 pages

Comments

Comment Entry

Name:

Email:

Location:

URL:

Remember my personal information

Notify me of follow-up comments?

Statistics

  • Total Entries - 136
  • Current Viewers - 26

Categories

Entries by Day

Sep - 2010
S M T W T F S
29 30 31 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 1 2

Recent Comments

Syndicate