Skip to main content
Participant
July 31, 2023
Answered

Acrobat instance still running after closing using VBA

  • July 31, 2023
  • 1 reply
  • 924 views

I have exhaustively searched for an answer, with limited success.

 

I open a document from Excel using:

 

Set AcroApp = CreateObject("AcroExch.App")
Set AvDoc = CreateObject("AcroExch.AVDoc")

'Open temporary file
AvDoc.Open "C:\Users\saylork\Documents\Waste Pickup Temp.pdf", ""
Set AcroForm = CreateObject("AFormAut.App")
Set Fields = AcroForm.Fields

 

After extracting data, I attempt to close it using:

Set Fields = Nothing
Set AcroForm = Nothing
AvDoc.Close True
AcroApp.CloseAllDocs
AcroApp.Exit
Set AcroApp = Nothing
Set AvDoc = Nothing

 

I've tried various ordering of the above just in case that made a difference, nope.

 

Also tried (APIs at top of code):

 

Sub CloseAdobeReader()
Dim strClassName As String
Dim hwnd As Long

strClassName = "AcrobatSDIWindow"
hwnd = FindWindow(strClassName, vbNullString)
If hwnd Then
SendMessage hwnd, WM_CLOSE, 0, ByVal 0&
Else
MsgBox "Adobe is not running!"
End If
End Sub

 

This will force a shut down. However, I'm opening and closing in a loop. It works the first time through (imports and closes), misses the second (no import, returns message) and works the third.

 

Is there a reliable way to close it?

This topic has been closed for replies.
Correct answer BarlaeDC

HI,

There is not a reliable way to close in this workflow, I have not found a good way it is always something like what you have, although I tend to add a delay between the end of the run and the start of the next ( it does delay things) but that way you make sure Acrobat can shutdown and restart before you start processing.

 

 

1 reply

BarlaeDC
Community Expert
BarlaeDCCommunity ExpertCorrect answer
Community Expert
August 18, 2023

HI,

There is not a reliable way to close in this workflow, I have not found a good way it is always something like what you have, although I tend to add a delay between the end of the run and the start of the next ( it does delay things) but that way you make sure Acrobat can shutdown and restart before you start processing.