Results 1 to 2 of 2

Thread: VBA in Access to close all open PowerPoint presentations

  1. #1
    VBAX Regular
    Oct 2013

    VBA in Access to close all open PowerPoint presentations

    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?

  2. #2
    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
        Next pptPres
        ' Quit PowerPoint application
        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.
    Last edited by Aussiebear; 11-02-2023 at 01:23 PM. Reason: Added code tags to supplied code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts