Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Close OLE Word object

Posted on 2002-05-28
3
244 Views
Last Modified: 2010-05-02
In one of my functions I open a Word instance.
My problem is that after I finish with that instance and set it to nothing its the Word process is still active(I can see it in the task manager)
What I do wrong?

The code:
Function WordFunc(TextValue)
        Dim objDocobject
        Dim strReturnValue
        Dim objWordobject As New Word.Application
        objWordobject.Visible = True
        Set objWordobject = CreateObject("word.Application")
        Set objDocobject = objWordobject.Documents.Add(, , 1, True)
        objDocobject.Content = TextValue

        objDocobject.Close False
        Set objDocobject = Nothing
        objWordobject.Application.Quit True
        Set objWordobject = Nothing      
    WordFunc= TextValue
End Function
0
Comment
Question by:alto
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
ID: 7038901
You declare AS NEW which is not good. Anyway, declaring as OBJECT will not allow you to have the nice coding help, but should solve your problem.

Function WordFunc(TextValue)
       Dim objDocobject
       Dim strReturnValue
       Dim objWordobject As Object
       objWordobject.Visible = True
       Set objWordobject = CreateObject("word.Application")
       Set objDocobject = objWordobject.Documents.Add(, , 1, True)
       objDocobject.Content = TextValue

       objDocobject.Close False
       Set objDocobject = Nothing
       objWordobject.Application.Quit True
       Set objWordobject = Nothing      
   WordFunc= TextValue
End Function

CHeers
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7038916
Indeed the issue is that you are actually declaring two instances of the word.application object, one with the Set .. As New Word.Application and one with the CreateObject Call.

If you either follow angelIII's advice and declare as object or

Function WordFunc(TextValue)
      Dim objDocobject
      Dim strReturnValue
      Dim objWordobject As Word.Application
      objWordobject.Visible = True
      Set objWordobject = CreateObject("word.Application")
      Set objDocobject = objWordobject.Documents.Add(, , 1, True)
      objDocobject.Content = TextValue

      objDocobject.Close False
      Set objDocobject = Nothing
      objWordobject.Application.Quit True
      Set objWordobject = Nothing      
  WordFunc= TextValue
End Function

Without the New keyword it should be fine.
0
 

Author Comment

by:alto
ID: 7038918
simple as that :)
Tnx'
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question