Welcome to MSDN Blogs Sign in | Join | Help

Visual How to: Automating PowerPoint 2007 Using a Custom Task Pane

Learn how to to create a custom task pane that automates Microsoft Office PowerPoint 2007. In this Visual How to, Harry shows you how to create a custom task pane that inserts dates into a slide when the user clicks a MonthCalendar control that is on the custom task pane.

 

 

-- Kathleen

Published Wednesday, May 02, 2007 4:21 PM by kmcgrath

Comments

# re: Visual How to: Automating PowerPoint 2007 Using a Custom Task Pane

Kathleen,

I have your VSTO for Mere Mortals book and have found it very useful.  I've been using VSTO 2005 SE and now VSTO 3.0 and have had good results.  I hate to ask a question in a blog, but I can't seem to find an answer.  I am using VSTO to create a present custom save dialogs for SharePoint.  Everything works great for Word and Excel (2007), but PowerPoint is giving me a problem: whenever I call SaveAs or even SaveCopyAs, it immediately displays the default dialog.  Is there a way to prevent this, as I'd like to bypass the default dialog all-together.  I know you're busy, but if you happen to get an alert on this post, it would be great.

Thanks again for the great book,

Gary

Thursday, May 22, 2008 2:48 PM by dwarfnebula

# re: Visual How to: Automating PowerPoint 2007 Using a Custom Task Pane

Hi Gary,

I'm glad the book has been helpful in learning VSTO. Because I'm not familiar with VSTO 3.0's support for PowerPoint, I forwarded your question to the VSTO team to see if they could help. Without seeing code or understanding exactly what you're trying to accomplish, it's hard to make recommendations.  A writer on the VSTO team created a test add-in that uses Presentation.SaveAs and Presentation.SaveCopyAs, and neither caused a built-in dialog to display.

Because your question is related to functionality of PowerPoint itself (rather than VSTO functionality), you might try posting your question to the PowerPoint newsgroup at http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.powerpoint It would be helpful to provide the code that is causing the problem when you post your question.

You can also take a look at the VBA/Developer Documentation at http://msdn.microsoft.com/en-us/library/bb187389.aspx.  

If you don't get the answer you need after using these resources, you can e-mail me at kmcgrath @ microsoft.com with more specifics and I'll see if I can help you find a solution.

--Kathleen

Thursday, May 22, 2008 7:50 PM by kmcgrath

# re: Visual How to: Automating PowerPoint 2007 Using a Custom Task Pane

Kathleen,

Thanks for your response.  I posted my question in the Office Developer --> Add-Ins forum.  But in its simplest form, here is the entirety of the sample code that generates the issue.

private void ThisAddIn_Startup(object sender, System.EventArgs e)

       {

           this.Application.PresentationBeforeSave += new

Microsoft.Office.Interop.PowerPoint.EApplication_PresentationBeforeSaveEventHandler(Application_PresentationBeforeSave);

       }

       void

Application_PresentationBeforeSave(Microsoft.Office.Interop.PowerPoint.Presentation Pres, ref bool Cancel)

       {

           Pres.SaveAs("c:\\PowerPointPres.pptx",

Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsXMLPresentation,

               Microsoft.Office.Core.MsoTriState.msoFalse);

           Cancel = true;

       }

When the Pres.SaveAs call is made, the default SaveAs dialog is displayed.  Also, I set a breakpoint at the Cancel = true line, and it is never hit.  Processing in that method appears to halt as soon as SaveAs is called.

Thanks very much,

Gary

Friday, May 23, 2008 10:06 AM by dwarfnebula

# re: Visual How to: Automating PowerPoint 2007 Using a Custom Task Pane

Thanks Gary. A VSTO writer (McLean) did some research and thinks this might be by design behavior of PowerPoint.  He notes:

"When I tried his exact code, the call to Pres.SaveAs in the PresentationBeforeSave event handler throws a COMException.  

I presume the exception is why the following Cancel = true line in his code is never being reached. If he isn't seeing the exception, he should go to Debug->Exceptions and check the Thrown box for Common Language Runtime Exceptions, or add try/catch blocks to his code."

He found some information about this at http://www.xtremevbtalk.com/archive/index.php/t-210840.html.  

In particular, the thread notes "it seem that for both Word and Excel it is possible to cancel the saveas and, whilst still in the "beforesave" event, issue a request to the office product to save the document to a specified location. You can't do that with PowerPoint the SaveAs commend always fails if your in the "beforeSave" thread. Both situations should get you into trouble. What is happening is that you are creating infinite-recursion, and if there were no protections in place, you would get a Stack Overflow Error, which is generally fatal."

According to this thread, you might be able to get around this by calling SaveAs on a different thread, or use a timer to call SaveAs after the PresentationBeforeSave event is raised.

I hope this helps!

Kathleen

Saturday, May 24, 2008 12:21 AM by kmcgrath

# re: Visual How to: Automating PowerPoint 2007 Using a Custom Task Pane

Kathleen,

I cannot thank you enough for you and the rest of the team's help on this; it is invaluable.  I will continue to work on this, and if you'd like, I'll post what I find out.

Thank you again,

Gary

Tuesday, May 27, 2008 9:03 AM by dwarfnebula

# re: Visual How to: Automating PowerPoint 2007 Using a Custom Task Pane

Thank you very much for the VSTO for Mere Mortals.

book. It has helped me a lot as a quick intro to vb.net and VSTO programming. Having done a lot of programming in good old VB6 and VBA I've started to learn VSTO quite recently. It's really fun and so exciting to explore the huge possibilities with VSTO. These videos are awesome as well.

Wednesday, July 01, 2009 3:43 PM by Ulrik
Anonymous comments are disabled
 
Page view tracker