locked
Powerpoint VBA New Slide Problem RRS feed

  • Question

  • Hi Guys :) I am having problem in vba.  I am adding new slide by this function.
    Dim Pre As Presentation
        Dim Sld As Slide
         
        Set Pre = ActivePresentation
        Set Sld = Pre.Slides.Add(Index:=Pre.Slides.Count + 1, Layout:=ppLayoutText)
    After Slide ads i want to insert picture in it automatically with his code.
       ActiveWindow.Selection.SlideRange.Shapes.AddPicture( _
       FileName:="C:\Program Files\Microsoft Office\Templates\Add In\side.png", _
       LinkToFile:=msoFalse, _
       SaveWithDocument:=msoTrue, Left:=0, Top:=0, _
       Width:=90, Height:=ActiveWindow.Presentation.PageSetup.SlideHeight).Select
    But i get compile error, so please help me :)
    Friday, February 14, 2014 7:18 AM

Answers

  • Hi,

    Are you sure the FileName parameter of the AddPicture Method is correctly? If not, please correct it.

    If you get a compile error when adding a picture into the slide, I assume the issue may be related to the Selection object or the FileName parameter since I think the code is OK. So are you sure there is a slide selected or you have selected the specify slide after inserting it? If not, it will throw a compile error. You could try "Sld.Select" behind Slides.Add method or do that manually.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 17, 2014 5:36 AM

All replies

  • Hello Irakli,

    What compile error do you get? Could you please be more specific?

    The following line of code contains six property and method calls:

       ActiveWindow.Selection.SlideRange.Shapes.AddPicture( _
       FileName:="C:\Program Files\Microsoft Office\Templates\Add In\side.png", _
       LinkToFile:=msoFalse, _
       SaveWithDocument:=msoTrue, Left:=0, Top:=0, _
       Width:=90, Height:=ActiveWindow.Presentation.PageSetup.SlideHeight).Select

    I'd recommend breaking the chain of calls into separate lines and then locate the problematic line of code.

    Friday, February 14, 2014 10:37 AM
  • Hi,

    Are you sure the FileName parameter of the AddPicture Method is correctly? If not, please correct it.

    If you get a compile error when adding a picture into the slide, I assume the issue may be related to the Selection object or the FileName parameter since I think the code is OK. So are you sure there is a slide selected or you have selected the specify slide after inserting it? If not, it will throw a compile error. You could try "Sld.Select" behind Slides.Add method or do that manually.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 17, 2014 5:36 AM