closing an external application from excel

piero1975

Board Regular
Joined
Nov 20, 2002
Messages
56
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
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Haluk

Rules Violation
Joined
Oct 26, 2002
Messages
1,075
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
 

PureFire

Board Regular
Joined
Jun 11, 2003
Messages
56
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]
 

Watch MrExcel Video

Forum statistics

Threads
1,123,269
Messages
5,600,629
Members
414,396
Latest member
rinianjell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top