PPT2002: PowerPoint and the Visual Basic Editor Do Not Quit as Expected on the Application.Quit Event (285467)



The information in this article applies to:

  • Microsoft PowerPoint 2002

This article was previously published under Q285467

SYMPTOMS

When you run a Microsoft Visual Basic for Applications (VBA) macro from within the Visual Basic Editor that includes an Application.Quit event, Microsoft PowerPoint 2002 and the Visual Basic Editor may not quit as expected. The same macro does cause Microsoft PowerPoint 2000 and the Visual Basic Editor to quit.

CAUSE

This behavior occurs when all of the following conditions are true:
  • The macro closes the active presentation.

    -and-
  • The Application.Quit event occurs after the active presentation is closed.

    -and-
  • The presentation that the macro belongs to is not the last presentation open.
For example, the following macro in a presentation, if run from the Visual Basic Editor and not from PowerPoint, exhibits the behavior described in the "Symptoms" section:
Sub A()
   For Each oPres In Application.Presentations
	If Not oPres.Saved And oPres.Path <> "" Then 
           oPres.Save
        Else
           oPres.Saved = True
        End If
	oPres.Close
   Next
   Application.Quit
End Sub
				
If there are four presentations open when this code is run, and the presentation that the macro is associated with is the third one in the Window menu's list of open presentations, the fourth presentation remains open.

PowerPoint 2000 retains the macro in memory until it is finished running. PowerPoint 2002, on the other hand, unloads the macro from memory the instant that the presentation that holds it is closed when the macro is run from the Visual Basic Editor.

WORKAROUND

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site: For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site: To work around this issue, remove the command that closes the active presentation. The earlier sample macro can be changed to the following sample, in which case, PowerPoint and the Visual Basic Editor quit as expected.
Sub A()
   For Each oPres In Application.Presentations
	If Not oPres.Saved And oPres.Path <> "" Then 
           oPres.Save
        Else
           oPres.Saved = True
        End If
   Next
   Application.Quit
End Sub
				

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbbug kbpending KB285467