Results 1 to 3 of 3

Thread: Closing MS Word in VB application

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2001
    Posts
    153

    Cool 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.

  2. #2
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    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

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    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
  •  



Click Here to Expand Forum to Full Width