簡體   English   中英

Excel到Powerpoint(但帶有表格而不是圖片)

[英]Excel to Powerpoint (But with tables not pictures)

我正在嘗試使用在Excel中創建的表自動創建PowerPoint。 我的問題是表格粘貼到Powerpoint中之后,就不會立即將其視為“已選擇”。 我收到一個錯誤,通常說類似“未選擇對象”或“對象“選擇”的方法“ ShareRange”失敗”之類的錯誤。 如果我慢慢地使用F8遍歷代碼,那么它在大多數情況下都可以運行,但是在它運行時卻無法正常工作。

無論如何,我都嘗試過使用表的名稱(當表中的副本獲得名稱“表1”時,可以想象),我嘗試使它等待幾秒鍾和其他一些事情。 我嘗試了不同類型的粘貼到文件中,但是我需要將其保留為表格而不是圖片(如果只需要圖片,我的代碼可以工作)。 我的問題(我認為)是粘貼並且沒有立即選擇。

我已經對其進行了一些修改,只是在顯示錯誤在哪里,我也反復進行同樣的粘貼,移動,調整大小。 我真的希望這是一條線-因為明顯可以解決問題,所以可以拍打我的臉...

    Dim pp As PowerPoint.Application
    Dim PPPres As PowerPoint.Presentation
    Dim PPSlide As PowerPoint.Slide
    Dim Slide1Title As Excel.Range
    'Opening a blank, normally I have it open a template
    Set pp = New PowerPoint.Application
    Set PPPres = pp.Presentations.Add
    Set PPSlide = PPPres.Slides.Add(1, 12)
    Set PPSlide = PPPres.Slides.Add(2, 12)
    Set PPSlide = PPPres.Slides.Add(3, 12)
    pp.Visible = True


   'Paste as text/table
   'Title 1
    PPPres.Slides(2).Select
    Set Slide1Title = Sheets("presentation").Range("B2:G3")
    Slide1Title.Copy
    PPPres.Application.CommandBars.ExecuteMso ("PasteSourceFormatting")
    'Here-ish is the error, after pasting in I can't seem to select it
    pp.ActiveWindow.Selection.ShapeRange.Top = 10
    pp.ActiveWindow.Selection.ShapeRange.Left = 75

常見問題。 最近粘貼的形狀將始終位於“頂部”,因此您可以使用如下所示的形狀:

PPPres.Slides(2).Shapes(PPPres.Slides(2).Shapes.Count)

請注意,通過選擇形狀和滑塊,您可以打開自己的頁面,以免遇到奇怪的錯誤,並使代碼的運行速度降低一個數量級。

Dim oSh as Shape
With PPPres.Slides(2)
  ' Do the paste, then get a reference to the pasted shape:
  Set oSh = PPPres.Slides(2).Shapes(PPPres.Slides(2).Shapes.Count)
  With oSh
     ' set .Top, .Left etc
  End With   ' the shape
End With  ' the slide

不使用F8時的臨時解決方案

Set Slide1Title = Sheets("presentation").Range("B2:G3")
Slide1Title.Copy
PPPres.Slides(2).Select
With PPPres.Slides(2)
PPPres.Application.CommandBars.ExecuteMso ("PasteSourceFormatting")
MsgBox ("1")
Set oSh = PPPres.Slides(2).Shapes(PPPres.Slides(2).Shapes.Count)

    With oSh
pp.ActiveWindow.Selection.ShapeRange.Top = 10
pp.ActiveWindow.Selection.ShapeRange.Left = 75
    End With   ' the shape
End With  ' the slide

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM