none
Closing PDF files that are open via VBA

    Question

  • RE: Access 2003

    In my application (via command button) I have successfully launched Adobe Reader with a PDF file. 

    The user can have multiple pdf's open (up to 4).

    Does anyone have a VBA code example that will   1) check to see if Adobe Reader is active in the Task Manager, and then 2) close file "12-3456.pdf", but leave other .pdf files open for the user to view?

    thanks

    RLN


    RLN

    Friday, March 23, 2012 1:00 PM

Answers

All replies

    • Marked as answer by RLN60 Tuesday, March 27, 2012 9:52 PM
    Friday, March 23, 2012 1:28 PM
  • Thank you!

    (I was actually thinking it would be a little simpler, but I guess not.)


    RLN

    Friday, March 23, 2012 1:39 PM
  • Got it to working!  Thank you for your help here!

    RLN

    Tuesday, March 27, 2012 9:52 PM
  • Using the code from these links:

    http://www.mvps.org/access/api/api0007.htm
    http://www.mvps.org/access/api/api0013.htm
    http://www.mvps.org/access/api/api0025.htm

    ......initially worked for closing one window, but now the requirement has changed.  The user wants to close multiple .pdf windows.

    (RE: Access 2003/  Adobe Reader X ver. 10.1.2)

    When I process contracts in my app, I display .pdf files related to that contract for the user while they process the current contract.

    When I go from contract #1 to contract #2, contract #1's .pdf file windows need to be closed.
    I have no problem opening Adobe Reader and displaying the pdf file, that works very nicely. 

    The problem is in closing multiple open .pdf file windows.  Up to two .pdf files can be opened and displayed for any given contract being processed

    Per the Debug window example here, I need to modify my code to where I can close *all* the open .pdf Adobe Reader sessions for the previous contract
    where the class = "AcrobatSDIWindow" and
    Caption = "<strPrevContractNum>.pdf" and "<strPrevContractNum>.-Invoice.pdf" 
    -------
    From the Debug window:
    Class = AcrobatSDIWindow    Caption = 5-22894.pdf - Adobe Reader
    Class = AcrobatSDIWindow    Caption = 5-22894-Invoice.pdf - Adobe Reader
    Class = AcrobatSDIWindow    Caption = 5-22893-Invoice.pdf - Adobe Reader
    -------

    Per the debug window example, I processed contract 5-22894.pdf first.
    Then I launched contract 5-22893.  At the time I launched file "893", I need to close both of the other .pdf files from the previous contract, 5-22894.

    Currently, the code listed below will only close the most recently opened .pdf file.

    Any suggestions would be helpful...thanks.

    These functions I am using:  fEnumWindows,  fIsAppRunning and   fCloseApp  all came from the mvps.org links above.

    Here is the code I am using currently:

    <begin code>

    ------------------------------
    Public Sub ClosePDF()

    'interrogates to see if Adobe Reader is running in the taskbar and if it is,
    'this routine will close the Adobe Reader session that is currently running...

    On Error GoTo Err1
        'Close the .pdf file for this contract if it is currently opened...
        fEnumWindows   'get the class names for opened windows in task bar
        Dim blnResult As Boolean
        blnResult = fIsAppRunning("AdobeAcrobat")
        If blnResult = True Then
            fCloseApp ("AcrobatSDIWindow")
        End If

    Exit1:
        Exit Sub

    Err1:
        MsgBox Err.Number & "--" & Err.Description, vbOKOnly, gblPgmName & "--" & "ClosePDF()"
        Resume Exit1

    End Sub

    '---------------

    <end code>


    RLN

    Thursday, April 12, 2012 4:19 PM
  • Well I'm using other aproach.

    I'm using dde call to acrobat.

        DDEChan = DDEInitiate("Acroview", "Control")
        DDEExecute DDEChan, "[FilePrintSilent(" & Chr(34) & fullPath & Chr(34) & ")]"
        Pause (60)
        DDEExecute DDEChan, "[AppExit()]"
        DDETerminate DDEChan

    IN acrobat X they chaneged Acroview to acroviewR10

    • Proposed as answer by Andreg52 Sunday, March 30, 2014 8:44 AM
    Thursday, April 12, 2012 4:30 PM
  • I have not used DDE before in my VBA code.  If you have two open .pdf files, how does your DDE code here close *both* of those sessions instead of just the one most recently opened?   How is "DDEChan" and DDEExecute declared?  (what is the syntax?) 


    RLN

    Thursday, April 19, 2012 6:33 PM
  • For the reader it's AcroviewR10

    for the app it's AcroviewA10


    • Edited by Andreg52 Sunday, March 30, 2014 9:08 AM
    Sunday, March 30, 2014 8:44 AM