user3390169
user3390169

Reputation: 1045

PowerPoint Macro - Paste Slides and Keep Source Formatting

I have a core set of slides that I insert into all of my presentations saved on my desktop. I wrote a macro that copies those slides and pastes them into the current open presentation but I lose the source formatting. I read some other posts that do similar things but I can't seem to get the ExecuteMso command to work:

Sub insertSlides()
    
    Dim objPresentation As Presentation
    Dim currPresentation As Presentation
    Set currPresentation = Application.ActivePresentation
    
    Set objPresentation = Presentations.Open("C:\Users\Me\Desktop\coreSlides.pptx", , False)
    objPresentation.Slides.Item(1).Copy
    currPresentation.Application.CommandBars.ExecuteMso ("PasteSourceFormatting")
    objPresentation.Close
    
 End Sub

Also, can you use this command to always paste a slide after slide 2?

Upvotes: 2

Views: 1832

Answers (1)

codeDom
codeDom

Reputation: 1769

I added one line to your code and it works great for me, and pasted the slide while keeping the original format. currPresentation.Windows.Item(1).Activate

But the size of the slide is not saved, if you need it you can set it explicitly according to the size in the original presentation.

Sub insertSlides()
    
    Dim objPresentation As Presentation
    Dim currPresentation As Presentation
    Set currPresentation = Application.ActivePresentation
    
    Set objPresentation = Presentations.Open("F:\1.pptx", , False)
    objPresentation.Slides.Item(1).Copy
    currPresentation.Windows.Item(1).Activate ' NEW LINE !
    currPresentation.Application.CommandBars.ExecuteMso ("PasteSourceFormatting")
    objPresentation.Close
    
 End Sub

Upvotes: 1

Related Questions