Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Mar 2004
    Location
    Knoxville, Tennessee, USA
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Closing WINWORD.EXE Within VB6 Program (VB6)

    I utilize VB6 to open and save many Microsoft Word XP documents each day. I open Word with the following code:

    Dim ObjWord As Object

    Set ObjWord = CreateObject("Word.Basic")
    With ObjWord

    I close the program with:

    ExitHandler:
    On Error Resume Next
    Set ObjWord = Nothing
    ObjWord.Quit
    Set ObjWord = Nothing
    Exit Sub

    I have noticed when I open Task Manager that there are numerous instances of WINWORD.EXE that are present. Is there anything I can do to completely close the WINWORD.EXE files when I close the VB6 program? As always, thank you!

    Bob Nichols

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Closing WINWORD.EXE Within VB6 Program (VB6)

    You're setting objWord = Nothing and THEN you're issuing objWord.Quit, and then another objWord = Nothing. Take out the first one. You can't issue a quit command when you've already destroyed the object reference.
    Charlotte

  3. #3
    New Lounger
    Join Date
    Mar 2004
    Location
    Knoxville, Tennessee, USA
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Closing WINWORD.EXE Within VB6 Program (VB6)

    Thank you Charlotte! I made the suggested change, i.e deleted the first instance of "Set ObjWord = Nothing", but the Task Manager still contained a WINWORD.EXE. Upon repeating the procedure, I got yet another WINWORD.EXE. Am I missing something? I am assuming it is not a good thing to have a dozen instances of WINWORD.EXE running at the same time. I would greatly appreciate any further guidance. Thank you!

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Closing WINWORD.EXE Within VB6 Program (VB6)

    No, it isn't a good thing. Did you check to make sure all instances of Winword were ended before you tried it again? From only the snippet of code you posted, I don't think it's possible to determine why Winword is staying open. Can you post more of the automation code so that someone might spot the problem?
    Charlotte

  5. #5
    New Lounger
    Join Date
    Mar 2004
    Location
    Knoxville, Tennessee, USA
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Closing WINWORD.EXE Within VB6 Program (VB6)

    I will attach a Microsoft Word Document which contains all code set forth in the Command Button which utilizes WordXP. In order to make it a little more readable I have paginated it in Legal Size and in Landscape mode. Even then some lines of code have spilled over to a second line. I have highlighted in "red" some areas of interest. However, I obviously do not seem to know which lines of code are important. Please note that this command opens more than one (1) Word Template. Again, your help is greatly appreciated! Thank you!

    Bob Nichols

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Closing WINWORD.EXE Within VB6 Program (VB6)

    The inconsistent indentation makes it too hard for me to find out what your code does.

    I would consider using Word VBA instead of WordBasic. Although WordBasic is still available for compatibility, VBA has been the standard programming language for Word since Word 97. You can use code like this to activate or start Word:

    Dim wrdApp As Word.Application
    Dim blnStartWord As Boolean

    On Error Resume Next
    ' See if Word is already active
    Set wrdApp = GetObject(, "Word.Application")
    If wrdApp Is Nothing Then
    ' No, so start a new instance
    Set wrdApp = CreateObject("Word.Application")
    If wrdApp Is Nothing Then
    ' Failed
    MsgBox "Cannot activate Word."
    Exit Sub
    End If
    blnStartWord = True
    End If
    On Error GoTo 0 ' or to an error handler

    The blnStartWord flag lets you keep track of whether you started a new instance of the Word application.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •