Copy from Excel to Powerpoint error

前端 未结 2 1630
别跟我提以往
别跟我提以往 2020-12-12 05:31

Again with the help of the kind resources around stackoverflow, I have been using the code below to copy information from Excel 2010 into Powerpoint 2010 slides. I repeat th

相关标签:
2条回答
  • 2020-12-12 06:06

    The problem that you are facing is because the copying is taking time and the next line is getting executed and it doesn't find anything in the clipboard to paste.

    Two ways to handle this problem

    Way 1

    XLApp.Range("WS1Dash").Copy
    DoEvents
    Set ppShape = PPSlide.Shapes.PasteSpecial(DataType:=ppPasteOLEObject, Link:=msoFalse)
    

    Way 2

    XLApp.Range("WS1Dash").Copy
    Wait 2
    Set ppShape = PPSlide.Shapes.PasteSpecial(DataType:=ppPasteOLEObject, Link:=msoFalse)
    

    And paste this at the bottom of your procedure

    Private Sub Wait(ByVal nSec As Long)
        nSec = nSec + Timer
        While nSec > Timer
            DoEvents
        Wend
    End Sub
    

    Lemme know if this doesn't help...

    0 讨论(0)
  • 2020-12-12 06:07

    I was having the same problem and it happened as I was trying to export from Excel to PowerPoint without the PowerPoint reference, using it as object. The tricky thing was that sometimes it worked, other times it won´t. So after some testing I found out that it depends on the state of the PowerPoint View, if it is showing Thumbnails or a normal Slide view.

    To fix it, set the ViewType as normal before pasting.

    PPAP.ActiveWindow.ViewType = ppViewNormal
    

    or

    PPAP.ActiveWindow.ViewType = 9
    

    PPAP stands for PowerPoint Application Object.

    0 讨论(0)
提交回复
热议问题