如何在VBA中将具有特定位置的图表从excel导出到ppt?

时间:2015-06-15 11:00:45

标签: vba excel-vba powerpoint-vba excel

Sheets("Slide Name").ChartObjects("Object 8").Select

Selection.Copy

   mySlide.Select

数据类型为ppPasteOLEObject,而非ppPasteEnhancedMetafile

mySlide.Shapes.PasteSpecial DataType:=ppPasteOLEObject, _
       Link:=msoTrue

以下代码无效。

   Set myShapeRange = mySlide.Shapes(mySlide.Shapes.Count)

      myShapeRange.Left = 234
      myShapeRange.Top = 186

如何在PowerPoint中选择特定图表并重新定位?

1 个答案:

答案 0 :(得分:0)

这个简短的测试正常。

Option Explicit

Sub test()
    Dim objSlide As Slide
    Dim objPresentation As Presentation
    Dim objShape As Shape
    Dim objApplication As Excel.Application
    Dim objWorkbook As Workbook
    Dim objWorksheet As Worksheet

    Set objApplication = New Excel.Application
    Set objWorkbook = objApplication.Workbooks.Open("c:\@Test\Chart.xlsx")
    Set objWorksheet = objWorkbook.Worksheets(1)
    Set objPresentation = ActivePresentation
    Set objSlide = objPresentation.Slides(1)
    objWorksheet.ChartObjects("Chart 1").Select

    objApplication.Selection.Copy

    objSlide.Select
    objSlide.Shapes.PasteSpecial DataType:=ppPasteOLEObject, Link:=msoTrue

    Set objShape = objSlide.Shapes(objSlide.Shapes.Count)
    objShape.Left = 100
    objShape.Top = 100
End Sub

获取形状对象时可以有一个断点,并试一试。粘贴操作始终在列表末尾添加一个新项目。