简体   繁体   English

使用VBA将图表从Excel导出到Powerpoint

[英]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. 所以经过一些挖掘后,我得到了一些帮助,找到一个代码将图表从Excel导出到Powerpoint,问题是它只是选择一个对象。

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. 它选择的对象是一个更大的图表(对象本身被命名)内的图表/ vlookup图像结果,所以基本上它只获得项目本身的一小部分。

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). 此外,我想知道如何修改此代码以添加到现有的Powerpoint(假设现有的Powerpoint已经打开)。

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. 如果您只是想显示一个基于excel工作簿内容更新的图表,您可以简单地复制图表,并在两者之间创建链接。 When both your presentation and workbook are open it will update the chart automatically with no need for VBA. 当您的演示文稿和工作簿都打开时,它将自动更新图表而无需VBA。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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