Came up with a "solution".
Seems too simple to be correct.
For the code below, one needs a Userform with 3 buttons.
1. Shut down any running PowerPoint.
2. Click on the Create PPT button.
3. After the program creates a PPT session, create a PPT session via the GUI, not using the icon minimized by the code.
4. Click on the Close PPT button.
5. Click on the Bye Bye button.
This code would appear to work for those cases in which my code need not keep a presentation alive. So, if I close all the code's presentations, this method appears to work.
If I have to keep a presentation alive, that should be no problem as I just would not close PowerPoint, just set its object variable = Nothing.
Does this hanky panky solve the problem?
Option Explicit
Private appPPT As Powerpoint.Application
Private blnNewPPT As Boolean
' Private MyPrivateName As String
Private Sub btnByeBye_Click()
Unload Me
End Sub
Private Sub btnClosePPT_Click()
With appPPT
If blnNewPPT Then
If .Presentations.Count = 0 Then
.Quit
lstActions.AddItem "New instance was Quit."
Else
lstActions.AddItem "New instance was NOT Quit."
End If
Else
On Error Resume Next
.ActivePresentation.Close
On Error GoTo 0
lstActions.AddItem "Extant instance was not Quit."
End If
End With
Set appPPT = Nothing
lstActions.AddItem "Set instance = Nothing."
On Error Resume Next
lstActions.AddItem Err.Number & ":" & Err.Description
On Error GoTo 0
End Sub
Private Sub btnCreatePPT_Click()
'Get existing instance of PowerPoint; otherwise create a new one
On Error Resume Next
Set appPPT = GetObject(, "PowerPoint.Application")
lstActions.AddItem Err.Number & ":" & Err.Description
If Err.Number = 0 Then
blnNewPPT = False
lstActions.AddItem "Extant instance is being used."
Else
Set appPPT = New Powerpoint.Application
blnNewPPT = True
lstActions.AddItem "New instance was created."
End If
With appPPT
' MyPrivateName = "HK" & Now & CDbl(Now)
.Visible = True
.WindowState = ppWindowMinimized
lstActions.AddItem "Presentations Count: " & .Presentations.Count
End With
On Error GoTo 0
End Sub