closing an external application from excel

Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: closing an external application from excel

  1. #1
    Board Regular piero1975's Avatar
    Join Date
    Nov 2002
    Location
    italia
    Posts
    56
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    Join Date
    Oct 2002
    Location
    Turkey
    Posts
    1,023
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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]

User Tag List

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