Well, I've just run a test in PowerPoint 97, 2000, 2002, and 2003.
Same resuls in all four (with 1 exception in, surprise!, PPT 97),
It appears that there's NEVER a REQUIREMENT to use Quit or to set the PPT
object to nothing. Indeed, one can get in trouble doing so.
Of course, one might wish to do so in the context of a larger/longer running
app to free resources,
BUT, as my headbanging these past few weeks has confirmed, it is NEVER safe
to release a PPT object, especially if one's code created a NEW instance, as
such an action could
wipe other uses of PPT, in particualr thaose started by other code.
The only case that bothers me is when you create a NEW non-visible instance
of PPT in code AND then some other code creates another non-visible intance
which adds a presentation (not visible because the PPT is not
visible), if you shut down the code WITHOUT a QUIT, PPT goes away anyway.
However, this does not occur with PPT 97. Idendependently of whether one
likes the idea of PPT affecting another session with a non-visible
presentation, that's a rather significant difference between PPT 97 and
later versions, You'd think that the Officve 2000 documentation would have
pointed this out. Has it? I've not checked.
The code I used for my test is given below, it's a hack, so it's not pretty.
Put the code in a VB 6 Form.
Form has 7 buttons and 1 listbox:
btnPPTNew: "Create New PPT"
btnWordNew: "Create New Word"
btnPPTVisible: "Start a Visible PPT"
btnPPTNonVisible: "Start a Non-Visible PPT"
btnPPTNonVisibleWithPresentation: "Start a Non-Visible PPT with
presentation"
btnByeBye: "ByeBye!"
btnClearList: "Clear List"
lstActions
A file named PPTTest.txt is created in the directory in which the code is
executed.
Use the Task Manger to watch when PowerPoint is created/deleted.
' Author: Howard Kaikow
' Author URL:
http://www.standards.com/
' Date: 11 June 2005
Option Explicit
Private Const LB_SETHORIZONTALEXTENT = &H194
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private appPPTOriginal As PowerPoint.Application
Private appPPTVisible As PowerPoint.Application
Private appPPTNonVisible As PowerPoint.Application
Private appPPTNonVisibleWithPresentation As PowerPoint.Application
Private appWord As Word.Application
Private intFile As Integer
Private Sub btnPPTNonVisibleWithPresentation_Click()
Dim presPPT As PowerPoint.Presentation
On Error Resume Next
Set appPPTNonVisibleWithPresentation = GetObject(,
"PowerPoint.Application")
If Err.Number = 0 Then
Print #intFile, "PowerPoint: Another non-Visible, with presentation,
instance was created."
lstActions.AddItem "PowerPoint: Another non-Visible, with
presentation, instance was created."
Debug.Print "PowerPoint: Another non-Visible, with presentation,
instance was created."
Set presPPT = appPPTNonVisibleWithPresentation.Presentations.Add
Else
Print #intFile, "PowerPoint: Another non-Visible, with presentation,
Huh!"
lstActions.AddItem "PowerPoint: Another non-Visible, with
presentation, Huh!"
Debug.Print "PowerPoint: Another non-Visible, with presentation,
Huh!"
End If
On Error GoTo 0
btnPPTNonVisibleWithPresentation.Visible = False
End Sub
Private Sub btnPPTNew_Click()
On Error Resume Next
'Check if PowerPoint is running
Do
Set appPPTOriginal = GetObject(, "PowerPoint.Application")
If Err.Number = 0 Then
If vbCancel = MsgBox("Stop all running instances of PowerPoint,
and then choose Retry to continue this test." _
& vbCrLf & vbCrLf & "Or choose Cancel to cancel this test.",
vbInformation + vbRetryCancel, "PowerPoint is currently running") Then
Unload Me
Exit Sub
End If
Else
Err.Clear
Exit Do
End If
Loop
' Verify that PowerPoint is still not running
Set appPPTOriginal = GetObject(, "PowerPoint.Application")
If Err.Number = 0 Then
MsgBox "PowerPoint is still running", vbInformation + vbOK, "Test
cancelled"
Unload Me
Else
Set appPPTOriginal = New PowerPoint.Application
Print #intFile, "PowerPoint: New non-visible instance was created."
lstActions.AddItem "PowerPoint: New non-visible instance was
created."
Debug.Print "PowerPoint: New non-visible instance was created."
btnPPTNew.Visible = False
btnPPTVisible.Visible = True
btnPPTNonVisible.Visible = True
btnPPTNonVisibleWithPresentation.Visible = True
End If
On Error GoTo 0
btnClearList.Visible = True
End Sub
Private Sub btnPPTVisible_Click()
On Error Resume Next
Set appPPTVisible = GetObject(, "PowerPoint.Application")
If Err.Number = 0 Then
Print #intFile, "PowerPoint: Visible instance was created."
lstActions.AddItem "PowerPoint: Visible instance was created."
Debug.Print "PowerPoint: Visible instance was created."
appPPTVisible.Visible = True
Else
Print #intFile, "PowerPoint: Visible Huh!"
lstActions.AddItem "PowerPoint: Visible Huh!"
Debug.Print "PowerPoint: Visible Huh!"
End If
On Error GoTo 0
btnPPTVisible.Visible = False
End Sub
Private Sub btnPPTNonVisible_Click()
On Error Resume Next
Set appPPTNonVisible = GetObject(, "PowerPoint.Application")
If Err.Number = 0 Then
Print #intFile, "PowerPoint: Another non-Visible instance was
created."
lstActions.AddItem "PowerPoint: Another non-Visible instance was
created."
Debug.Print "PowerPoint: Another non-Visible instance was created."
Else
Print #intFile, "PowerPoint: Another non-Visible Huh!"
lstActions.AddItem "PowerPoint: Another non-Visible Huh!"
Debug.Print "PowerPoint: Another non-Visible Huh!"
End If
On Error GoTo 0
btnPPTNonVisible.Visible = False
End Sub
Private Sub btnWordNew_Click()
On Error Resume Next
'Check if Word is running
Do
Set appWord = GetObject(, "Word.Application")
If Err.Number = 0 Then
If vbCancel = MsgBox("Stop all running instances of Word, and
then choose Retry to continue this test." _
& vbCrLf & vbCrLf & "Or choose Cancel to cancel this test.",
vbInformation + vbRetryCancel, "Word is currently running") Then
Unload Me
Exit Sub
End If
Else
Err.Clear
Exit Do
End If
Loop
' Verify that Word is still not running
Set appWord = GetObject(, "Word.Application")
If Err.Number = 0 Then
MsgBox "Word is still running", vbInformation + vbOK, "Test
cancelled"
Unload Me
Else
Set appWord = New Word.Application
Print #intFile, "Word: New non-visible instance was created."
lstActions.AddItem "Word: New non-visible instance was created."
Debug.Print "Word: New non-visible instance was created."
Print #intFile, "Word: New non-visible instance was NOT Quit."
lstActions.AddItem "Word: New non-visible instance was NOT Quit."
Debug.Print "Word: New non-visible instance was NOT Quit."
Print #intFile, "Word: Use Task Manager to end WinWord.exe."
lstActions.AddItem "Word: Use Task Manager to end WinWord.exe."
Debug.Print "Word: Use Task Manager to end WinWord.exe."
btnWordNew.Visible = False
End If
On Error GoTo 0
End Sub
Private Sub Form_Load()
btnClearList.Visible = False
btnPPTVisible.Visible = False
btnPPTNonVisible.Visible = False
btnPPTNonVisibleWithPresentation.Visible = False
intFile = FreeFile
Open "PPTTest.txt" For Output As #intFile
End Sub
Private Sub Form_Activate()
With lstActions
SendMessage .hWnd, LB_SETHORIZONTALEXTENT, _
ScaleX(.Width, vbTwips, vbPixels) + 150, ByVal 0&
End With
End Sub
Private Sub btnByeBye_Click()
Dim PPTCount As Long
QuitPPT
Unload Me
End Sub
Private Sub QuitPPT()
If TypeName(appPPTOriginal) = "Application" Then
With appPPTOriginal
' Non-visible uses of PowerPoint added AFTER this code created
NEW non-visible
' instance get killed if there is no VISIBLE use of PowerPoint.
If .Presentations.Count = 0 Then
Print #intFile, "PowerPoint: (0)New non-visible instance was
NOT Quit."
lstActions.AddItem "PowerPoint: (0)New non-visible instance
was NOT Quit."
Debug.Print "PowerPoint: (0)New non-visible instance was NOT
Quit."
Else
Print #intFile, "PowerPoint: (not 0)New non-visible instance
was NOT Quit."
lstActions.AddItem "PowerPoint: (not 0)New non-visible
instance was NOT Quit."
Debug.Print "PowerPoint: (not 0)New non-visible instance was
NOT Quit."
End If
End With
End If
End Sub
Private Sub btnClearList_Click()
lstActions.Clear
End Sub
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
Close #intFile
On Error GoTo 0
End Sub