Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
avi avi is offline
external usenet poster
 
Posts: 195
Default How to Close an application?

Hello,

I open an application via this code thaht works fine
Sub LaunchCaptureExpress()
Dim RetVal As Long
RetVal = Shell("C:\Program Files\Capture
Express\capexp.exe", vbNormalFocus)
End Sub

How do i close it???

Thanks a lot


Avi
www.avibenita.com


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 139
Default How to Close an application?

Hi ,Avi

try it!

close the Windows after 10 seconds

Sub LaunchCaptureExpress()
Dim WshShell As Object
Dim oExec As Object
Set WshShell = CreateObject("Wscript.Shell")
Set oExec = WshShell.Exec("C:\Program Files\Capture Express\capexp.exe")
DoEvents
Application.Wait (Now + TimeValue("0:00:10"))
oExec.Terminate
Set WshShell = Nothing
Set oExec = Nothing
End Sub

--
http://www.vba.com.tw/plog/


"Avi" wrote:

Hello,

I open an application via this code thaht works fine
Sub LaunchCaptureExpress()
Dim RetVal As Long
RetVal = Shell("C:\Program Files\Capture
Express\capexp.exe", vbNormalFocus)
End Sub

How do i close it???

Thanks a lot


Avi
www.avibenita.com



  #3   Report Post  
Posted to microsoft.public.excel.programming
avi avi is offline
external usenet poster
 
Posts: 195
Default How to Close an application?

Hi,

Thanks for your prompt answer

When doing what you advise, I get an error 'activex can't create object'.
I've added a reference, but the same error remains


Please help

Avi

Avi Benita 054-4660641 wwwAvi Benita 054-4660641 www.avibenita.com
"chijanzen" wrote in message
...
Hi ,Avi

try it!

close the Windows after 10 seconds

Sub LaunchCaptureExpress()
Dim WshShell As Object
Dim oExec As Object
Set WshShell = CreateObject("Wscript.Shell")
Set oExec = WshShell.Exec("C:\Program Files\Capture
Express\capexp.exe")
DoEvents
Application.Wait (Now + TimeValue("0:00:10"))
oExec.Terminate
Set WshShell = Nothing
Set oExec = Nothing
End Sub

--
http://www.vba.com.tw/plog/


"Avi" wrote:

Hello,

I open an application via this code thaht works fine
Sub LaunchCaptureExpress()
Dim RetVal As Long
RetVal = Shell("C:\Program Files\Capture
Express\capexp.exe", vbNormalFocus)
End Sub

How do i close it???

Thanks a lot


Avi
www.avibenita.com





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default How to Close an application?

This code will do it:

Public Declare Function GetDesktopWindow Lib "user32" () As Long

Public Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, _
ByVal wCmd As Long) As Long

Public Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" _
(ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long

Public Declare Function GetClassName Lib "user32" _
Alias "GetClassNameA" _
(ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long

Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDLAST = 1
Public Const GW_HWNDNEXT = 2
Public Const GW_HWNDPREV = 3
Public Const GW_OWNER = 4
Public Const GW_CHILD = 5
Const WM_CLOSE = &H10

Private Declare Function PostMessage Lib "user32" _
Alias "PostMessageA" (ByVal hwnd As
Long, _
ByVal wMsg As
Long, _
ByVal wParam As
Long, _
lParam As Any) As
Long


Private Declare Function getWindowsDirectory _
Lib "kernel32" _
Alias "GetWindowsDirectoryA" (ByVal lpBuffer
As String, _
ByVal nSize As
Long) As Long

Function FindWindowHwndLike(hWndStart As Long, _
ClassName As String, _
WindowTitle As String, _
level As Long, _
lHolder As Long) As Long

'finds the first window where the class name start with ClassName
'and where the Window title starts with WindowTitle, returns Hwnd
'----------------------------------------------------------------
Dim hwnd As Long
Dim sWindowTitle As String
Dim sClassName As String
Dim r As Long

'Initialize if necessary. This is only executed
'when level = 0 and hWndStart = 0, normally
'only on the first call to the routine.
If level = 0 Then
If hWndStart = 0 Then
hWndStart = GetDesktopWindow()
End If
End If

'Increase recursion counter
level = level + 1

'Get first child window
hwnd = GetWindow(hWndStart, GW_CHILD)

Do Until hwnd = 0
'Search children by recursion
lHolder = FindWindowHwndLike(hwnd, _
ClassName, _
WindowTitle, _
level, _
lHolder)

'Get the window text
sWindowTitle = Space$(255)
r = GetWindowText(hwnd, sWindowTitle, 255)
sWindowTitle = Left$(sWindowTitle, r)

'get the class name
sClassName = Space$(255)
r = GetClassName(hwnd, sClassName, 255)
sClassName = Left$(sClassName, r)

If InStr(1, sWindowTitle, WindowTitle, vbBinaryCompare) 0 And _
sClassName Like ClassName & "*" Then
FindWindowHwndLike = hwnd
lHolder = hwnd
Exit Function
End If

'Get next child window
hwnd = GetWindow(hwnd, GW_HWNDNEXT)

Loop

FindWindowHwndLike = lHolder

End Function

Function CloseApp(ByVal strApp As String, _
ByVal strClass As String) As Long

'will find a window based on:
'the partial start of the Window title and/or
'the partial start of the Window class
'and then close that window
'for example, this will close Excel:
'CloseApp "", "XLM" and this will:
'CloseApp "Microsoft Excel", ""
'but this won't: CloseApp "", "LM"
'it will only close the first window that
'fulfills the criteria
'will return Hwnd if successfull, and 0 if not
'---------------------------------------------

Dim hwnd As Long

On Error GoTo ERROROUT

hwnd = FindWindowHwndLike(0, _
strClass, _
strApp, _
0, _
0)

If hwnd = 0 Then
CloseApp = 0
Exit Function
End If

'Post a message to the window to close itself
'--------------------------------------------
PostMessage hwnd, WM_CLOSE, 0&, 0&

CloseApp = hwnd

Exit Function
ERROROUT:

On Error GoTo 0
CloseApp = 0

End Function


RBS


"chijanzen" wrote in message
...
Hi ,Avi

try it!

close the Windows after 10 seconds

Sub LaunchCaptureExpress()
Dim WshShell As Object
Dim oExec As Object
Set WshShell = CreateObject("Wscript.Shell")
Set oExec = WshShell.Exec("C:\Program Files\Capture
Express\capexp.exe")
DoEvents
Application.Wait (Now + TimeValue("0:00:10"))
oExec.Terminate
Set WshShell = Nothing
Set oExec = Nothing
End Sub

--
http://www.vba.com.tw/plog/


"Avi" wrote:

Hello,

I open an application via this code thaht works fine
Sub LaunchCaptureExpress()
Dim RetVal As Long
RetVal = Shell("C:\Program Files\Capture
Express\capexp.exe", vbNormalFocus)
End Sub

How do i close it???

Thanks a lot


Avi
www.avibenita.com




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to close Excel Application in IE Pommy Excel Discussion (Misc queries) 3 November 24th 05 03:36 PM
Close the other application Lulu Excel Programming 1 December 16th 04 05:43 PM
macro to close excel application other than application.quit mary Excel Programming 1 September 14th 04 03:43 PM
Application.Close Nichevo Excel Programming 3 December 23rd 03 03:33 PM


All times are GMT +1. The time now is 09:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"