简体   繁体   中英

Exporting chart from Excel to Powerpoint using VBA

So after a bit of digging I got some help to find a code to export a chart from Excel to Powerpoint, problem is it is only selecting an object.

Sub ertert()
    With New PowerPoint.Application
        With .Presentations.Add
            With .Slides.Add(1, 12)
                ActiveSheet.ChartObjects(1).CopyPicture xlPrinter, xlPicture
                .Shapes.Paste
                .Shapes(1).Select
                .Application.ActiveWindow.Selection.ShapeRange.Align msoAlignMiddles, True
                .Application.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
            End With
        End With
    End With
End Sub

the object it's selecting is a chart/vlookup image result inside of a larger chart (the object itself is named) so basically it's only getting a small part of the item itself.

Question is where I went wrong in having it only select an item? Also I would like to know how to modify this code to add to an existing Powerpoint (assuming the existing one is already open).

What exactly are you trying to do?

If you are just looking to display a chart that updates based on the content of your excel workbook you can simply copy the chart across and it creates a link between the two. When both your presentation and workbook are open it will update the chart automatically with no need for VBA.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM