Excel VBA 2010在粘贴到Powerpoint后选择和移动表的问题(Excel VBA 2010 issue with selecting and moving table after pa

编程入门 行业动态 更新时间:2024-10-23 15:21:39
Excel VBA 2010在粘贴到Powerpoint后选择和移动表的问题(Excel VBA 2010 issue with selecting and moving table after pasting into Powerpoint)

我有下面的代码,我在网上找到了从excel粘贴到powerpoint的代码。 将表粘贴到幻灯片后,它在PPSlide.Shapes(1).Select上失败。 PPSlide.Shapes(1).Select运行时错误'-2147188160(80048240)':Shape.Select:Invalide请求。 要选择形状,其视图必须处于活动状态。 我一直在寻找和尝试不同的东西,但似乎无法搞清楚..我认为在粘贴后表将处于活动状态并且代码将继续jsut但它不会,除非我激活/选择表中的幻灯片,然后单击运行。 任何帮助表示赞赏。 谢谢。

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

I have the code below which I found online to copy paste a tble from excel to powerpoint. After pasting the table into the slide, it fails on PPSlide.Shapes(1).Select with a Run-time error '-2147188160 (80048240)': Shape.Select : Invalide request. To select a shape, its view must be active. I've been searching and trying different things but can't seem to figure it out.. I thought after the paste that the table would be active and the code would jsut continue but it doesn't unless I activate/select the table in the slide and then click Run. Any help is appreciated. Thanks.

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

Try the code below:

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

更多推荐

本文发布于:2023-07-30 22:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340357.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Powerpoint   Excel   VBA   issue   table

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!