Excel VBA 2010在粘贴到Powerpoint后选择和移动表的问题

时间:2017-05-03 12:46:03

标签: excel vba powerpoint

我有下面的代码,我在网上找到了从excel粘贴到powerpoint的代码。将表格粘贴到幻灯片后,它在LinearLayout linearLayout = FindViewById<LinearLayout>(Resource.Id.linearLayout); ViewTreeObserver vto = linearLayout.ViewTreeObserver; vto.GlobalLayout += (sender, args) => { System.Console.WriteLine (linearLayout.Height); }; 上失败并出现运行时错误&#39; -2147188160(80048240)&#39;:Shape.Select:Invalide请求。要选择形状,其视图必须处于活动状态。 我一直在寻找和尝试不同的东西,但似乎无法解决这个问题。我认为在粘贴后表格会活跃并且代码会继续但是它不会,但除非我激活/选择幻灯片中的表格,然后单击“运行”。任何帮助表示赞赏。感谢。

PPSlide.Shapes(1).Select

1 个答案:

答案 0 :(得分:1)

尝试以下代码:

Set pp = CreateObject("PowerPoint.Application")
Set ppPres = pp.Presentations.Open(DestinationPPT)
pp.Visible = True

' first set the Slide and select it
SlideCount = ppPres.Slides.Count
Set ppSlide = ppPres.Slides.Add(SlideCount, 12)
ppSlide.Select

' have the Copy part right beofre youe Paste it to PowerPoint
Set Rng = ActiveSheet.Range("CA1:CJ" & Count + 1)
Rng.Copy

pp.ActivePresentation.Application.CommandBars.ExecuteMso ("PasteSourceFormatting")

Dim myShape As Object
' set up the Pasted shape to an object
Set myShape = ppSlide.Shapes(ppSlide.Shapes.Count)

With myShape
    ' set-up the shape properties

End With