|
-
May 18th, 2001, 06:51 AM
#1
Thread Starter
Addicted Member
Closing MS Word in VB application
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.
-
May 18th, 2001, 06:56 AM
#2
Registered User
Sure thing, enjoy :
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
-
May 18th, 2001, 07:47 AM
#3
_______
<?>
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
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|