My project opens multiple instances of MSWord. All I want is to close
all those windows when I close my window.
Will any one help me out?
Cheers,
Venkat.
Printable View
My project opens multiple instances of MSWord. All I want is to close
all those windows when I close my window.
Will any one help me out?
Cheers,
Venkat.
Sure thing, enjoy :D:
Option Explicit
Code:Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private 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
Private Const WM_CLOSE = &H10
Private Const WM_DESTROY = &H2
Private Const WM_NCDESTROY = &H82
Private Const WM_QUIT = &H12
Private Sub Command1_Click()
Call CloseApplication("opusapp")
End Sub
Sub CloseApplication(ByVal sClassName As String)
Dim happ As Long
happ = FindWindow(sClassName, vbNullString)
Do While happ
PostMessage happ, WM_CLOSE, 0, 0
PostMessage happ, WM_DESTROY, 0, 0
PostMessage happ, WM_NCDESTROY, 0, 0
PostMessage happ, WM_QUIT, 0, 0
happ = FindWindow(sClassName, vbNullString)
Loop
End Sub
If you are using the word object and
know the name(s) of the objects you open
'close objects [document and word]
objDoc.Close
objWord.Quit
'clear memory of the objects [documnent and word]
Set objDoc = Nothing
Set objWord = Nothing