Powerpoint exception during save operation

Add-in Express™ Support Service
That's what is more important than anything else

Powerpoint exception during save operation
 
Prashant Verma




Posts: 56
Joined: 2008-08-24
PowerPoint throws an exception when i want to save a document by a given path in PresentationBeforeSave event of adxPowerPointEvents without using windows save as dialog. Presently we are using Add in Express 2009 for .NET, Standard with product version: 5.2.2025


private void adxPowerPointEvents_PresentationBeforeSave(object sender, AddinExpress.MSO.ADXHostBeforeActionEventArgs e)
{
try
{
e.Cancel = true;
PowerPointApp.ActivePresentation.SaveAs("D:\\test.ppt", PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Office.MsoTriState.msoFalse);
}
catch (Exception ex)
{

}
}

This code returns with an error:

System.Runtime.InteropServices.COMException was unhandled by user code
HelpLink=""
Message="Presentation (unknown member) : Failed."
Source="Microsoft Office PowerPoint 2003"
ErrorCode=-2147467259
StackTrace:
at PowerPoint._Presentation.SaveAs(String FileName, PpSaveAsFileType FileFormat, MsoTriState EmbedTrueTypeFonts)

But this technique is applied in both word and excel and it works successfully.

But the same code works when i apply this in a button click.


void adxCommandBarButton1_Click(object sender)
{
try
{
PowerPointApp.ActivePresentation.SaveAs("D:\\test.ppt", PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Office.MsoTriState.msoFalse);

}
catch(Exception ex)
{

}
}

Is there a fix or how can I work around this issue?
Posted 14 Dec, 2010 11:19:11 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hi Prashant,

Unlike Word and Excel, PowerPoint doesn't allow saveASing in that event. You need to cancel the event, send a custom message using ADXAddinModule.SendMessage and quit the event handler. Then, in the OnSendMessage event of the add-in module, filter incoming messages; when you get your message, save the presentation. Note that the save will fire BeforePresentationSave anew. That is, you'll have to use a flag to distinguish between the initial BeforePresentationSave and the BeforePresentationSave caused by calling Presentation.SaveAs in your code.

SendMessage and OnSendMessage. Please find a code sample in the class reference or search through this forum, say, see http://www.add-in-express.com/forum/search.php?tags=&q=SendMessage+OnSendMessage+WM_USER&where=5


Andrei Smolin
Add-in Express Team Leader
Posted 14 Dec, 2010 11:43:11 Top