Solved

Close OLE Word object

Posted on 2002-05-28
3
243 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 142

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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA color chart bars 12 87
TT Auto Dashboard 13 92
How to read File Date Created using VB6 8 40
RUNRMTCMD from AS/400 12 50
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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

832 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