Closing application (Acrobat, Word, Excel) after closing the last document
Solution 1
After some more tests, I need to both close and quit all document objects to ensure that the app quits if there is no remaining opened document.
Solution 2
I think you should add:
gApp.Exit
before the
Set gApp = Nothing
That seems to do the tick, but the app is still there, hidden... To Actually kill Acrobat try this method here with "Acrobat.exe": How can I kill task manager processes through VBA code? That method is a bit of a sledge hammer, but it works.
dan
Updated on June 04, 2022Comments
-
dan almost 2 years
I have a few functions that generate Word, Excel or PDF documents. For example, the one I'm working on is exporting a report to a PDF file. After closing the report, it opens another PDF form created with LiveCycle ES 8.2 and it fills it with data from a database. After this, the document is closed, but for some reason, the instance of Acrobat is still open in foreground with no document opened.
Here is the code:
DoCmd.OpenReport "myReport", acViewPreview DoCmd.OutputTo acOutputReport, "", acFormatPDF, "C:\myReport.pdf", False DoCmd.Close acReport, "myReport" Dim gApp, avDoc, pdDoc, jso Set gApp = CreateObject("AcroExch.app") Set avDoc = CreateObject("AcroExch.AVDoc") If avDoc.Open(exprPDF, "") Then Set pdDoc = avDoc.GetPDDoc() Set jso = pdDoc.GetJSObject '[...] pdDoc.Save PDSaveIncremental, FileNm 'Save changes to the PDF document pdDoc.Close 'Close the PDF document End If avDoc.Close (True) Set gApp = Nothing Set avDoc = Nothing
myReport never opens any instance of Acrobat. The line
avDoc.Open
does. I would like Acrobat to be closed when I doavDoc.close
. Any ideas? -
dan about 7 yearsI honestly haven't worked in that project in years and I am not doing any VBA anymore nowadays but this could be useful for other developers with similar problems I guess.
-
blablubbb about 7 yearsI just actually tried the code, but it just seems to work. After changing and saving 50 documents Acrobat complains that the maximum number of documents it can open is reached, despite no document is visibly open and I see the Acrobat program appear and disappear in the task bar. I even added a 'gApp.CloseAllDocs' before the exit statement just to make sure... additionally to closing the AVDoc and the PDDoc.