PowerPoint Ribbon becomes unresponsive

I'm creating an Add-in for PowerPoint 2010.  Building a feature to let the user save slides to a slide library, then later select and insert them, all without using SharePoint or the Reuse slides pane.

The save routine presents a list of categories and keywords the user can select, then upon Saving, my code opens the category deck, appends the slide to the end of that and adds keyword tags to that slide, saves and closes the category deck, and also logs the save to an Excel sheet using ADODB.  

When done, the PowerPoint ribbon has become non-responsive.  Won't accept any clicks.  If I resize my PowerPoint window, or switch to another application, I get control back.  But that's just a workaround.  Plus, next time I try my Save routine it crashes PowerPoint.

Anyone recognize this behavior and have a generic cause/solution?  I'd rather not post my full code.

Thanks!

Other references to this issue:
link1
Link2
Bryce BassettFreelance VBA programmerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bryce BassettFreelance VBA programmerAuthor Commented:
Just an update that this is happening in another section of my code where I am building the feature that inserts the slides from the library.  The thing it has in common with the other module is that I am using VBA to open another deck, copying a slide from there, pasting that slide into my currently open presentation, then closing the source deck.  Seems like these copy and paste operations may be the source of the troubles.  Same thing happens.  Ribbon goes to sleep.  I wake it back up by minimizing and maximizing, but then my macros behave strangely or crash PowerPoint altogether

Is there an alternate method to use to copy and paste slides that is more robust?  Even better, is there a way to copy slides from, or insert slides into, a presentation without having to first open it in PowerPoint?  Below is the approach I am using now.  Thanks!

currentslideindex = ActiveWindow.View.Slide.SlideIndex
Set targetdeck = ActivePresentation
deck2open = "some string" 
slide2copy = "some other string
set sourcedeck = Application.Presentations.Open(deck2open)
sourcedeck.Slides(slide2copy).Copy
currentslideindex = currentslideindex + 1
targetdeck.Slides.Paste (currentslideindex)
sourcedeck.Close

Open in new window

Jamie GarrochSenior Technical Consultant at BrightCarbonCommented:
I use the Presentations.Open method in a couple of my add-ins and have never come across this issue before.

However, I do specify that the window should not be shown (as there is no need for the user to see the source) so I'm wondering if that could be the cause. This is what I would use:

Application.Presentations.Open(deck2open, ReadOnly:=msoTrue, Untitled:=msoFalse, WithWindow:=msoFalse)

Open in new window


As far as I know, there is no way to get the content from a deck without opening it as VBA is relying on the underlying transformation of the XML representing the objects within a presentation before exposing them in the object model.
Bryce BassettFreelance VBA programmerAuthor Commented:
I'm making progress, thanks to your tip.  Opening withwinow = false did solve the problem in two instances, but not in a third.

My save routine now works for an existing deck.
'if existing deck, append slide to end of that deck and resave.
    Set existingdeck = Application.Presentations.Open(contentlibraryfolder & "\SlideLibrary\" & selectedtext & ".pptx", _
       Untitled:=msoFalse, WithWindow:=msoFalse)
    currentslide.Copy
    existingdeck.Slides.Paste
    existingdeck.Save
    existingdeck.Close

Open in new window


For a similar routine where I first create a new deck, I couldn't get it to work without first creating a new deck, doing a saveas, closing it, then reopening it per above, and now it works.  Kinda roundabout but I'll live with it.
'if new deck, create that deck.
    Set newdeck = Application.Presentations.Add(msoFalse)
    newdeck.Slides.Add index:=1, Layout:=ppLayoutTitle
    newdeck.SaveAs contentlibraryfolder & "\SlideLibrary\" & selectedtext & ".pptx"
    newdeck.Close
    Set newdeck = Nothing
    
    Set newdeck = Application.Presentations.Open(contentlibraryfolder & "\SlideLibrary\" & selectedtext & ".pptx", _
       Untitled:=msoFalse, WithWindow:=msoFalse)
    currentslide.Copy
    newdeck.Slides.Paste
    newdeck.Save
    newdeck.Close

Open in new window


But my insert routine below, which looks the same to me, is still freezing then crashing PowerPoint.  Can you spot how this is different?
 Set sourcedeck = Application.Presentations.Open(deck2open, ReadOnly = msoTrue, Untitled = msoFalse, WithWindow = msoFalse)
sourcedeck.Slides(slide2copy).Copy
currentslideindex = currentslideindex + 1
targetdeck.Slides.Paste (currentslideindex)
sourcedeck.Close
targetdeck.Slides(currentslideindex).Select

Open in new window


One weird thing is that if I stop my code after opening the sourcedeck above, is has the generic name "Presentation n" even though I say untitled = false.  Does that give any clue?

Thanks.
Jamie GarrochSenior Technical Consultant at BrightCarbonCommented:
For the first part, this works for me:

' Copy a slide to the clipboard before running
Sub EE_CreateDeck()
  Dim newdeck As Presentation
  
  Set newdeck = Application.Presentations.Add(msoTrue)
  newdeck.Slides.Paste (1)
  ' Add a breakpoint here to see the deck with a single pasted slide
  newdeck.Close
  Set newdeck = Nothing
End Sub

Open in new window


For the second part, can you add a breakpoint and then step through line by line and see which one is causing PowerPoint to crash?

I just looked at my own add-in code and I realised I have the Untitled property set to msoTrue (so true, true, false). Sorry.

You could also try leaving it without the Untitled property:

Application.Presentations.Open(deck2open, ReadOnly = msoTrue, , WithWindow = msoFalse)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bryce BassettFreelance VBA programmerAuthor Commented:
Thanks for all your help, Jamie.  I messed around with every combination of those attributes of the Open method, and that did not seem to fix things.  

With some further tinkering around I discovered/remembered (this happened to me a couple years back) that my problem had to do with an open userform, the one that invokes the insert routine.  I was leaving that box (Modal) open while trying to do these other operations of opening deck, copy, paste, close deck.  Apparently PowerPoint gets mixed up in all that switching and gets confused.  I'm sure there's a more technical explanation!   But my solution was to make that userform non-modal, and also hide it before starting the open, copy, paste, close, then re-show it at the end.  No more hang-ups!

Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft PowerPoint

From novice to tech pro — start learning today.