繁体   English   中英

Excel VBA 2010问题,粘贴到Powerpoint后选择并移动表格

[英]Excel VBA 2010 issue with selecting and moving table after pasting into Powerpoint

我有下面的代码,我在网上找到了将excel中的tble复制粘贴到powerpoint的代码。 将表格粘贴到幻灯片后,它在PPSlide.Shapes(1).Select上失败。 PPSlide.Shapes(1).Select时出现运行时错误'-2147188160(80048240)':Shape.Select:无效请求。 要选择形状,其视图必须处于活动状态。 我一直在搜索并尝试其他操作,但似乎无法弄清楚。.我想在粘贴之后,该表将处于活动状态,并且代码将继续运行,但除非激活/选择该表,否则它不会幻灯片,然后单击运行。 任何帮助表示赞赏。 谢谢。

Dim pp As Object
Dim PPPres As Object
Dim PPSlide As Object
Dim Rng As Range

DestinationPPT = "C:\Users\username\Desktop\Data_Display.pptx"
Set pp = CreateObject("PowerPoint.Application")
Set PPPres = pp.Presentations.Open(DestinationPPT)
pp.Visible = True
Set Rng = ActiveSheet.Range("CA1:CJ" & Count + 1)

Rng.Copy

SlideCount = PPPres.Slides.Count
Set PPSlide = PPPres.Slides.Add(SlideCount, 12)
pp.ActivePresentation.Application.CommandBars.ExecuteMso ("PasteSourceFormatting")

PPSlide.Shapes(1).Select
pp.ActiveWindow.Selection.ShapeRange.Align msoAlignTops, True
pp.ActiveWindow.Selection.ShapeRange.Top = 65
pp.ActiveWindow.Selection.ShapeRange.Left = 7.2
pp.ActiveWindow.Selection.ShapeRange.Width = 700

Set PPSlide = Nothing
Set PPPres = Nothing
Set pp = Nothing

请尝试以下代码:

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

暂无
暂无

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

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