0

I am working on exporting Contents from Excel to PowerPoint. I have a blank formatted slide in my PowerPoint presentation which I Need to duplicate everytime and write on it. The Problem is that my code adds a new slide ahead of the current slide which is posing Problems in writing the Contents to the exact slide number. I want that the new slide should be added after the current slide.

        Set pptSlide = oPPTApp.ActivePresentation.Slides(1).Duplicate.Item(1)
        oPPTFile.Slides(SlideNum).Select
        Set oPPTShape = oPPTFile.Slides(SlideNum).Shapes("Table 1")  

any Suggestions ?

5
  • Try removing .Item(1) from your first line. According to the documentation of .Duplicate(), pptSlide should be the second slide already. Commented Apr 14, 2016 at 13:44
  • @VerzweiflerAfter removing .Item(1), it gives a Type Mismatch Error as .Duplicate Returns a range and not a slide. Commented Apr 14, 2016 at 13:47
  • I'm not sure I understand the problem "my code adds a new slide ahead of the current slide" versus what you want "I want that the new slide should be added after the current slide". Also, are you trying to write to the duplicate slide or a different slide identified by SlideNum? If the later, how is SlideNum being set as adding a duplicate will change the indexing of the slides collection? Commented Apr 14, 2016 at 13:54
  • @JamieG I have a complex procedure of writing. In short there are places where I Need to increment the slide number and then there are places where the slide number remains the same. I am adding a duplicate slide, fetching ist slide number and then writing on it. That is why I want the duplicate slide to be added after the current slide, not before it Commented Apr 14, 2016 at 14:21
  • 1
    You already have a reference to the relevant slide (pptSlide) so why are you referring to the count of slides? Also posted: mrexcel.com/forum/excel-questions/… Commented Apr 14, 2016 at 14:38

2 Answers 2

2

There's almost NEVER a good reason to select anything when automating PPT. Assuming a shape named Table 1 on Slide 1, this should do what you want:

Dim oSl As Slide
Dim oSh As Shape

Set oSl = ActivePresentation.Slides(1).Duplicate()(1)
Set oSh = oSl.Shapes("Table 1")
Sign up to request clarification or add additional context in comments.

Comments

0

ActivePresentation.Slides.Range(1).Cut

ActivePresentation.Slides.Paste -1

this function will move the first slide to the last. so it stands to reason you could figure out a formula to keep track of where you want the slide inserted. if you need to know how many slides are in the range it's ActivePresentation.Slides.Range.count

1 Comment

should be better with example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.