Search code examples
vbapowerpointoffice-2010

Copy Excel table to Powerpoint returns run-time error '13'


I am really struggling with this, I don't seem to be able to find the reason for my code not working:

Dim i1 As Integer
Dim PPapp As Object, XLapp As Object
Dim slide1 As Slide, slide2 As Slide, slide3 As Slide
Dim PPoutput As Presentation
Dim output_table As ShapeRange
Set PPapp = New PowerPoint.Application
Set XLapp = Excel.Application
Set PPoutput = PPapp.Presentations.Open("Q:\SDPMaler\blank.potx", untitled:=msoTrue, withwindow:=msoTrue)
Set slide1 = ppoutput.Slides.AddSlide(1, ppoutput.SlideMaster.CustomLayouts(13))
XLapp.ActiveWorkbook.Sheets("PPT output").Range("y4:ae11").Copy
Set output_table = slide1.Shapes.PasteSpecial(ppPasteJPG, msoFalse, "", 1, "", msoTrue)

And here my code fails: The macro creates the powerpoint, adds the slide in the right layout and even pasts the table as picture

.PasteSpecial(DataType:=ppPasteOLEObject, link:=msoTrue)

works the same way, but with either I get "Run-time error '13': Type mismatch" on the last row of the pasted code. Even though #13 is usually an easy error to find I am really stuck this time. Hope someone can help me Thanks P.S.: II am using Office 2010 and am running the macro in Excel


Solution

  • My guess:

    Change this:

    Dim output_table As ShapeRange

    To:

    Dim output_table As PowerPoint.ShapeRange

    assuming you've set a reference to PowerPoint, or

    Dim output_table As Object

    if you're using late binding

    By dimming it as ShapeRange in Excel, you're creating a variable to hold an Excel shaperange, but when you paste into PPT, you get a PowerPoint shaperange, which would lead to a type mismatch.