none
Adding a Picture to a programmatically created PowerPoint presentation RRS feed

  • Question

  • Hello everybody,

    I'm trying to run a simple Word macro that creates a new PowerPoint presentation and simply adds a picture to the presentation from a predefined path. The code works more or less because the presentation file is opened correctly and the picture is added to the newly created slide but somehow I always get a runtime error '13' Type mismatch.

    If I write a macro that is used in a PowerPoint File to ad a picture to an existing presentation it works fine.

    Here is the code for the macro I use in Word:

    Option Explicit
    
    Sub TestMakro()
    '
    ' TestMakro Macro
    '
    '
          
    
          Dim oSld As Slide
          Dim oPic As Shape
    
          Dim testInlineShape As InlineShape
    
          Dim pptApp As PowerPoint.Application
          Dim pptPres As PowerPoint.Presentation
          
          Set pptApp = CreateObject("PowerPoint.Application")
          Set pptPres = pptApp.Presentations.Add(msoTrue)
    
          Set oSld = pptPres.Slides.Add(pptPres.Slides.Count + 1, ppLayoutBlank)
          Set oPic = oSld.Shapes.AddPicture("C:\Temp\data_files\image001.png", msoFalse, msoTrue, 100, 100)
          
    End Sub

    Thanks for your help.

    Jan

    Monday, November 14, 2016 3:54 PM

All replies

  • Hi Jan

    Try using

    Dim oPic As PowerPoint.Shape

    If not specified explicitly "Word.Shape" is used as type. As the PPT "AddPicture" method returns a PowerPoint shape this will lead to a type mismatch.

    You have no issue with the Dim statement for the "oSld" slide because no slide object exists in Word.

    Cheers, Luca

    Monday, November 14, 2016 4:40 PM
  • Thanks a lot. I tried the hole day to solve the problem. You saved me a lot of time.
    Monday, November 14, 2016 9:00 PM
  • Hi Epijano,

    From your last post it looks like your issue is solved by the suggestion given by Luca Brasi.

    but we notice that you did not mark his suggestion as an answer.

    so this thread is still open.

    please try to mark the suggestion as an answer it will help us to close this thread.

    otherwise thread will be open forever.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 23, 2016 2:26 AM
    Moderator