Close an application with vba

Ljb12668

New Member
Joined
Jul 20, 2003
Messages
4
I have workbook in which I open another program using the Shell statement. I want to close the other program as well when I close my excel spreadsheet. Does anyone know the command/code to do this.
Example: I open my workbook, it automatically opens a program called windwedge bu using Shell (C:\program files\winwedge.exe"). When I close my workbook I want windwedge to close also.

Thank You
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Give this a Try ???


You will need to KNOW the App Windows Caption
and substitute this in the Name


<font face=Courier New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>

<SPAN style="color:#007F00">'// used to find the Winwedge Window</SPAN>
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Declare</SPAN> <SPAN style="color:#00007F">Function</SPAN> FindWindow _
    <SPAN style="color:#00007F">Lib</SPAN> "user32" _
    Alias "FindWindowA" ( _
    <SPAN style="color:#00007F">ByVal</SPAN> lpClassName <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, _
    <SPAN style="color:#00007F">ByVal</SPAN> lpWindowName <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>) _
As <SPAN style="color:#00007F">Long</SPAN>

<SPAN style="color:#007F00">'// used to CLOSE the Winwedge App</SPAN>
<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Declare</SPAN> <SPAN style="color:#00007F">Function</SPAN> PostMessage _
    <SPAN style="color:#00007F">Lib</SPAN> "user32" _
    Alias "PostMessageA" ( _
    <SPAN style="color:#00007F">ByVal</SPAN> hWnd <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, _
    <SPAN style="color:#00007F">ByVal</SPAN> wMsg <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, _
    <SPAN style="color:#00007F">ByVal</SPAN> wParam <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, _
    lParam <SPAN style="color:#00007F">As</SPAN> Any) _
As <SPAN style="color:#00007F">Long</SPAN>

<SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Const</SPAN> WM_CLOSE = &H10

<SPAN style="color:#00007F">Sub</SPAN> TesterClose()
<SPAN style="color:#00007F">Dim</SPAN> lngRet <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> Pid <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>
<SPAN style="color:#00007F">Dim</SPAN> Winwedgehdl <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>

Shell "C:\program files\winwedge.exe"

Winwedgehdl = FindWindow(vbNullString, "The name as it appears in your App Title")
PostMessage Winwedgehdl, WM_CLOSE, 0&, 0&

<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

</FONT>
 
Upvote 0

Forum statistics

Threads
1,215,400
Messages
6,124,702
Members
449,180
Latest member
craigus51286

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
Back
Top