Avatar of jpp1jpp1
jpp1jpp1
 asked on

MS Word as a reporting tool. Winword.exe doesn't close

Title is pretty self-explanatory.

I'm using version 11 in my project's reference section (Vbasic 6.0) although, with the purpose to get an all-version compatible program, I'm actually using late-binding:

    Dim WordApp As Object
    Dim WordDoc As Object

    Set WordApp = CreateObject("Word.Application")
    Set WordDoc = CreateObject("Word.Document")


When the word template is filled I do the following for closing:

    WordDoc.Close
   
    WordApp.Quit
    Set WordDoc = Nothing
    Set WordApp = Nothing

But the winword.exe process isn't killed. In fact after generating several reports the same number of instances remain open, consuming more and more resources (loke 10M per instance)

Am I missing someting?

Ty in advance.
Visual Basic Classic

Avatar of undefined
Last Comment
jpp1jpp1

8/22/2022 - Mon
jpp1jpp1

ASKER
I just found out that my code is creating 2 instances of winword.exe thus .quit only closes one of them, but why?
jmundsack

Don't do createobject to get the document, do WordApp.Documents.Add:

    Dim WordApp As Object
    Dim WordDoc As Object

    Set WordApp = CreateObject("Word.Application")
    Set WordDoc = WordApp.Documents.Add

    '...

    WordDoc.Close
   
    WordApp.Quit
    Set WordDoc = Nothing
    Set WordApp = Nothing

jpp1jpp1

ASKER
Oops, I'm ashamed there was a second call to

      Set WordApp = CreateObject("Word.Application")

in my code. Sorry :P
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
jpp1jpp1

ASKER
What's the difference with WordApp.Documents.Add?
ASKER CERTIFIED SOLUTION
jmundsack

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
jpp1jpp1

ASKER
Ty for helping.