0
Dim myPresentation As Object
Dim mySlide As Object
Dim PowerPointApp As Object
Dim shp As Object
Dim MySlideArray As Variant
Dim MyRangeArray As Variant
Dim x As Long

PowerPointApp.ActiveWindow.Panes(1).Activate
Set myPresentation = PowerPointApp.ActivePresentation

MySlideArray = Array(1, 2)
MyRangeArray = Array(Worksheets("name").Range("A3:E17"), Worksheets("age").Range("A22:E37"))

For x = LBound(MySlideArray) To UBound(MySlideArray)
    MyRangeArray(x).Copy
    Set shp = myPresentation.Slides(MySlideArray(x)).Shapes.PasteSpecial(DataType:=2)
    Set myPresentation = PowerPointApp.ActivePresentation.AddSlide(PowerPointApp.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutBlank).Select

Next x

Question 1) The error is "Object doesn't support this prop or method" just at the Count+1.select line. What is my mistake?

Question 2) If i have two ranges of cells "A1:E9" and "A11:E20" in same sheet that i want to paste in same slide, is there a way to write code which looks for non-empty cells from A1 and copies data till the last filled row and paste in powerpoint?

Apologies for the long question. Will be happy to get any answer.

BigBen
  • 46,229
  • 7
  • 24
  • 40
Satvik K
  • 19
  • 4
  • You've already `Set myPresentation = PowerPointApp.ActivePresentation`... why are you trying to `Set myPresentation = ` again? `Set mySlide = myPresentation.AddSlide(myPresentation.Slides.Count + 1...` – BigBen Apr 03 '20 at 18:09
  • @BigBen - i tried your cmd and still the error persists. `mySlide` or `myPresentation` are both objects which have the property `addslide`. I don't get reason for the run-time error 438. – Satvik K Apr 03 '20 at 20:11
  • Sorry - my bad - it's [`Slides.AddSlide`](https://learn.microsoft.com/en-us/office/vba/api/powerpoint.slides.addslide) so should be `myPresentation.Slides.AddSlide`. – BigBen Apr 03 '20 at 20:22
  • There's several issues with that line.... writing up an answer. – BigBen Apr 03 '20 at 20:49

1 Answers1

1

Set myPresentation = PowerPointApp.ActivePresentation.AddSlide(PowerPointApp.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutBlank).Select

There's a couple things wrong with this:

  1. You already Set myPresentation = PowerPointApp.ActivePresentation previously. I think you meant mySlide.
  2. PowerPointApp.ActivePresentation - use myPresentation, this is redundant.
  3. The method is Slides.AddSlide, not Application.AddSlide or Presentation.AddSlide.
  4. ...but you want Slides.Add since AddSlide takes a CustomLayout as its second parameter.
  5. PowerPointApp.Slides.Count - there's no Slides property of the application; that should be myPresentation.Slides.Count.
  6. PowerPoint.PpSlideLayout.ppLayoutBlank - note that this early-binding, while the rest of your code uses late-binding. (Dim myPresentation As Object, Dim mySlide As Object, etc.). Best to be consistent. I've laid out an early-binding approach

With those revisions:

Const ppLayoutBlank as Long = 12

With myPresentation.Slides
    Set mySlide = .Add(.Count + 1, ppLayoutBlank)
End With
BigBen
  • 46,229
  • 7
  • 24
  • 40
  • @SatvikK - [this](https://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-excel-with-vba) may help with Question 2, but I'm not sure I understand exactly what the end goal is... it might be easier to ask a new question. – BigBen Apr 03 '20 at 21:28
  • 1
    i have posted my question here. https://stackoverflow.com/q/61022610/13119116. Thanks in advance. – Satvik K Apr 04 '20 at 01:12