Solved

Close OLE Word object

Posted on 2002-05-28
3
249 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
[X]
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
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

617 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