I made an PowerPoint VSTO Add-In with VisualBasic in Visual Studio with which I want to be able to copy all slides of a presentation and paste them with their original formatting into my currently active presentation. However it does not quite well work.
If I start up PowerPoint, create a new empty presentation, and click the Add-In it does not work. If I am in debug mode I get an runtime error which tells me "Presentation (unknown member): Object does not exist." at destPPT.Windows.Item(1).Activate()
(at the first time I try to use destPPT
). When I continue PowerPoint opens the presentation from which I wanted to copy the slides and closes the one I had active.
I found two ways to work around this in PowerPoint. The first one beeing to just close the opened presentation, create a new empty presentation and run the Add-In again. The other one is to modify anything in the empty presentation (like adding some text) and then running the Add-In. Both seem to work fine.
Here is a snippet of the code I used for this
Dim pptApp As Application
Dim destPPT As Presentation
Dim srcPPT As Presentation
pptApp = GetObject([Class]:="PowerPoint.Application")
destPPT = pptApp.ActivePresentation
srcPPT = pptApp.Presentations.Open(srcPath)
srcPPT.Slides.Range().Copy()
destPPT.Windows.Item(1).Activate()
destPPT.Application.CommandBars.ExecuteMso("PasteSourceFormatting")
srcPPT.Close()
I am new to Visual Basic and cant tell whats wrong or what I could do in a different way and couldnt find anything useful anywhere.