Solved

Close OLE Word object

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now