Solved

Close OLE Word object

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

751 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