簡體   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