Share via


Presentation Close event is incorrectly fired while issuing Presentation Print Command

Summary

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.

 

Cause

This is a known issue with PowerPoint 2003/ 2007.

 

Resolution

Either of the solutions mentioned below can be used to work around this issue:

Solution#1:

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)
    2:  { 
    3:      MessageBox.Show("applicationObject_PresentationPrint"); 
    4:  }
    5:   
    6:  void applicationObject_PresentationClose(Microsoft.Office.Interop.PowerPoint.PresentationPres)
    7:  {
    8:      if (!IsPrintPres(Pres))
    9:      {
   10:          //Write your code for presentation close event here. It will get executed only when a presentation is being closed.
   11:          MessageBox.Show("applicationObject_PresentationClose");
   12:      }
   13:  }
   14:   
   15:  private bool IsPrintPres(Microsoft.Office.Interop.PowerPoint.Presentation Pres)
   16:  {
   17:      foreach (Microsoft.Office.Interop.PowerPoint.Presentation p in applicationObject.Presentations)
   18:      {
   19:          if (p == Pres)
   20:          {
   21:              return false;
   22:          }
   23:      }
   24:      return true; 
   25:  }

Solution#2:

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)
    2:  {
    3:      MessageBox.Show("applicationObject_AfterPresentationOpen");
    4:      Pres.PrintOptions.PrintInBackground = MsoTriState.msoFalse;
    5:  }
    6:   
    7:  void applicationObject_AfterNewPresentation(Microsoft.Office.Interop.PowerPoint.Presentation Pres)
    8:  {
    9:      MessageBox.Show("applicationObject_AfterNewPresentation");
   10:      Pres.PrintOptions.PrintInBackground = MsoTriState.msoFalse;
   11:  }