Results 1 to 3 of 3

closing an external application from excel

This is a discussion on closing an external application from excel within the Excel Questions forums, part of the Question Forums category; hi, is there any mode for closing an external application from vb excel? In particular, i've opened a acrobat file ...

  1. #1
    Board Regular piero1975's Avatar
    Join Date
    Nov 2002
    Location
    italia
    Posts
    56

    Default closing an external application from excel

    hi,
    is there any mode for closing an external application from vb excel?
    In particular, i've opened a acrobat file (with command Set app = CreateObject("AcroExCh.App") ), in which i fill some field data; then i need to save it and close it whitout it displays any message (do you want to save..etc). If I had a excel application, i know that commands like "application.displayalerts = false" or "application.displaynoteindicator=false" suits me well, but working with an external (such as acrobat) is not so easy, i think.
    do you have any suggestion?
    Thank a lot

  2. #2
    Board Regular Haluk's Avatar
    Join Date
    Oct 2002
    Location
    Turkiye
    Posts
    832

    Default Re: closing an external application from excel

    Hi Pierro;

    I've opened a PDF file named AcrobatDoc.pdf
    When I opened this pdf file, the caption of the pdf window is :

    Acrobat Reader - [AcrobatDoc.pdf]

    So, by using this string in the caption of the pdf window (which should be exactly as seen on the caption), I used an Api call to find and close the pdf window.

    The related code is;

    Code:
    Declare Function FindWindow _
        Lib "user32" Alias "FindWindowA" ( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long
    
    Declare Function PostMessage _
        Lib "user32" Alias "PostMessageA" ( _
        ByVal hwnd As Long, _
        ByVal wMsg As Long, _
        ByVal wParam As Long, _
        ByVal lParam As Long) As Long
    '
    Sub ClosePDF()
    Call PostMessage(FindWindow(vbNullString, "Acrobat Reader - [AcrobatDoc.pdf]"), _
        16, 0, 0)
    End Sub

  3. #3
    Board Regular
    Join Date
    Jun 2003
    Posts
    56

    Default Re: closing an external application from excel

    You could always use SendKeys as below

    Code:
    Sub CloseApplication()
        AppActivate "Acrobat Reader - [AcrobatDoc.pdf]"  'Application title
        Application.Wait Now() + TimeSerial(0, 0, 1) 'Wait 1 second
        SendKeys "^q"  'CTRL + Q
    End Sub

    I use sendkeys alot and they work very nicely[/code]

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com