PDA

View Full Version : VBA in Access to close all open PowerPoint presentations



fkneg1
07-20-2023, 12:42 PM
Hi,
I have an Access database that produces a PowerPoint presentation depending on what is in certain fields. Part of it can copy and paste slides from other presentations in to the new one. For this bit to work properly, I have found that all open PowerPoints need to be closed before the code is run in Access which then lets it work fine. I thought it might be worth having some code at the start of the procedure in Access that closes all open PowerPoints before it starts anything else but I'm not sure where to start - any ideas?

hollylong
11-02-2023, 07:08 AM
Yes, you can use VBA code in your Access database to close all open PowerPoint presentations before running your code. Here's an example of how you can achieve this:


Sub CloseAllPowerPointPresentations()
Dim pptApp As Object ' PowerPoint.Application
Dim pptPres As Object ' PowerPoint.Presentation
' Check if PowerPoint is already open
On Error Resume Next
Set pptApp = GetObject(, "PowerPoint.Application")
On Error GoTo 0
' If PowerPoint is open, close all presentations
If Not pptApp Is Nothing Then
For Each pptPres In pptApp.Presentations
pptPres.Close
Next pptPres
' Quit PowerPoint application
pptApp.Quit
Set pptApp = Nothing
End If
' Clean up the objects
Set pptPres = Nothing
Set pptApp = Nothing
End Sub


You can call the CloseAllPowerPointPresentations subroutine at the beginning of your Access procedure to ensure that all open PowerPoint presentations are closed before continuing with your code.