错误 - 请求无效。要选择形状,其视图必须处于活动状态

时间:2014-03-30 19:39:57

标签: vba excel-vba powerpoint excel

我是VBA的新手。我正在编写代码来将excel中的粘贴图表复制到powerpoint演示文稿的不同幻灯片中。我可以在ppt的幻灯片1上粘贴图表,完美对齐;但对于第二张图表,我收到一条错误消息:“请求无效。要选择一个形状,其视图必须处于活动状态。”请求所有人支持我纠正以下代码:

Sub ExcelAuto()
Dim PPT As PowerPoint.Application
Dim PPTFile As PowerPoint.Presentation
Dim ActiveSlide As PowerPoint.Slide

Set PPT = CreateObject("PowerPoint.Application")
PPT.Visible = True
PPT.Presentations.Open fileName:="Path"

Set PPTFile = PPT.ActivePresentation
PPT.ActiveWindow.ViewType = ppViewSlide

        ActiveWorkbook.Sheets("Charts").ChartObjects("Chart 6").CopyPicture
        With PPTFile.Slides(1)
        .Shapes.Paste.Select
         PPT.ActiveWindow.Selection.ShapeRange.Left = 37
         PPT.ActiveWindow.Selection.ShapeRange.Top = 127
        End With

        ActiveWorkbook.Sheets("Charts").ChartObjects("Chart 8").CopyPicture
        With PPTFile.Slides(2)
        .Shapes.Paste.Select
         PPT.ActiveWindow.Selection.ShapeRange.Left = 37
         PPT.ActiveWindow.Selection.ShapeRange.Top = 354
        End With

    Set PPT = Nothing
    Set PPTFile = Nothing
    Set ActiveSlide = Nothing


End Sub

1 个答案:

答案 0 :(得分:4)

使用

ActiveWindow.View.GotoSlide oSlide.SlideIndex

在选择幻灯片上的形状之前激活视图:

可以找到更多信息here