When the print command of a PowerPoint Presentation is issued, the presentation.close event is fired in addition to the Print event・
However, the expected behavior is that the presentation.close event should not get fired when the print command is issued.
This is a known issue with PowerPoint 2003/ 2007.
Either of the solutions mentioned below can be used to work around this issue:
This solution exploits the fact that there is a temporary presentation created for the purpose of background printing and temporary presentations are not added to the list of open presentations.
So the workaround is to go through the list of presentations and if current presentation is not found there, then it is the temporary print presentation. The Close Event Handler would ignore the event in that case.
The sample code (c#) to implement the workaround is given below:
1: void applicationObject_PresentationPrint(Microsoft.Office.Interop.PowerPoint.PresentationPres)
6: void applicationObject_PresentationClose(Microsoft.Office.Interop.PowerPoint.PresentationPres)
8: if (!IsPrintPres(Pres))
10: //Write your code for presentation close event here. It will get executed only when a presentation is being closed.
15: private bool IsPrintPres(Microsoft.Office.Interop.PowerPoint.Presentation Pres)
17: foreach (Microsoft.Office.Interop.PowerPoint.Presentation p in applicationObject.Presentations)
19: if (p == Pres)
21: return false;
24: return true;
Explicitly set the background print option to false (either programmatically or manually). The sample code(C#) to programmatically set the background print option to false is given below:
1: void applicationObject_AfterPresentationOpen(Microsoft.Office.Interop.PowerPoint.Presentation Pres)
4: Pres.PrintOptions.PrintInBackground = MsoTriState.msoFalse;
7: void applicationObject_AfterNewPresentation(Microsoft.Office.Interop.PowerPoint.Presentation Pres)
10: Pres.PrintOptions.PrintInBackground = MsoTriState.msoFalse;