Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WINWORD.EXE Problem 3

Status
Not open for further replies.

Jack58

Technical User
May 6, 2002
91
0
0
US
I have a database that is converting text files into a Microsoft Word 2000 File. The problem that I am having is that WINWORD.EXE is not closing. I have used the following code to close the Text files, however I still have the problem of WINWORD remaining in my Taskbar and not allowing me to Open Word.

Kill strRootPath & CStr(Format(i, "00")) & "\" & strFile

If anyone needs to see the entire Database code or find out more information please contact me.

Hope someone can help me out with this frustrating problem.



Jack
 
That code is not just closing the Text files, but actually deleted them.

As far as Word not closing, how do you open Word, and what are you doing to try to close Word?

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
This is an error with your memory management by using early binding of variables. You must fully qualify every time you reference the objects you have instantiated. Click for more.
INFO: Error or Unexpected Behavior with Office Automation When You Use Early Binding in Visual Basic
Code:
Dim wApp As Word.Application
Dim wDoc As Word.Document

Set wApp = New Word.Application
Set wDoc = wApp.Documents.Add 'FULLY QUALIFY HERE

wApp.Selection.Font.Size = 12 'FULLY QUALIFY HERE
'Other code here, always fully qualify your calls
If Not wApp Is Nothing Then
   Set wApp = Nothing
End If

If Not wDoc Is Nothing Then
   Set wDoc = Nothing
End If
 
Cajun,

Here's the code Jack and i have been working on....I couldn't find the missing piece....

Code:
    ' Check for and delete any PrintOut.doc file remaining
    If Dir(strRootPath & "PrintOut.doc") = "PrintOut.doc" Then Call Kill(strRootPath & "PrintOut.doc")
    
    ' Open the PrintOut.txt file in Word, add page breaks, and save the file as PrintOut.doc"
    Set objWord = New Word.Application
    
    objWord.Documents.Open strPrint
    Selection.Find.Execute "1REPORT", , , , , , , , , "^m", wdReplaceAll
    With ActiveDocument.PageSetup
        .Orientation = wdOrientLandscape
        .TopMargin = InchesToPoints(0.5)
        .BottomMargin = InchesToPoints(0.5)
        .LeftMargin = InchesToPoints(0.2)
        .RightMargin = InchesToPoints(0.2)
    End With
    Selection.WholeStory
    Selection.Font.Name = "Arial"
    Selection.Font.Size = 9
    ActiveDocument.SaveAs strRootPath & "PrintOut.doc", wdFormatDocument
    'objWord.Visible = True
    'Documents("PrintOut.txt").Close
    Documents("PrintOut.doc").Close
    
    ' Print the PrintOut.doc file
    strLine = MsgBox("Do you wish to print the report?", vbYesNo, "Print?")
    If strLine = vbYes Then ActiveDocument.PrintOut
        
    Set objWord = Nothing

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Where you say
Code:
Selection.Find.Execute "1REPORT", , , , , , , , , "^m", wdReplaceAll

This must be fully qualified. There may be more, read up on that link I posted, it has a list of the methods which can cause this error.
 
Sorrry that did not work. Looked at the link and it does not apply to this problem.



Jack
 
I would suggest, then, to comment out everything from your function and add in line by line, until you figure out what is causing office not to close. Be sure your code has been changed to represent full qualification. I tested the code you posted earlier and it left word applications running, however after fully qualifying as below, it works correctly, minus the line for the execute, I don't have anything to try for that. I commented out the code I tried in case you want to see what I did to error check.

Code:
    ' Open the PrintOut.txt file in Word, add page breaks, and save the file as PrintOut.doc"
    'Dim objWord As Word.Application
    'Dim strPrint as String
    Set objWord = New Word.Application
    objWord.Visible = True
    
    'strPrint = "C:\trial.doc"
    objWord.Documents.Open strPrint
    objWord.Selection.Find.Execute "1REPORT", , , , , , , , , "^m", wdReplaceAll
    With objWord.ActiveDocument.PageSetup
        .Orientation = wdOrientLandscape
        .TopMargin = objWord.InchesToPoints(0.5)
        .BottomMargin = objWord.InchesToPoints(0.5)
        .LeftMargin = objWord.InchesToPoints(0.2)
        .RightMargin = objWord.InchesToPoints(0.2)
    End With
    objWord.Selection.WholeStory
    objWord.Selection.Font.Name = "Arial"
    objWord.Selection.Font.Size = 9
    objWord.ActiveDocument.SaveAs "PrintOut.doc", wdFormatDocument
    'objWord.Visible = True
    'objWord.Documents("PrintOut.txt").Close
    objWord.Documents("PrintOut.doc").Close
    
    ' Print the PrintOut.doc file
    'strLine = MsgBox("Do you wish to print the report?", vbYesNo, "Print?")
    'If strLine = vbYes Then objWord.ActiveDocument.PrintOut
    'objWord.Quit
    Set objWord = Nothing
 
I think the key element is

objWord.Quit - Missing from mstrmage1768 original posting, and commented out in Axoliien most recent post. Then

Set objWord = Nothing

I would also Close and Set all document objects to nothing before the quit and setting of the objWord object.


Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
To all....

I think that has done the trick. My tests seem to no be closing down word corectly. Thank you all. Cajun and Axoliien win the stars!

=======================================
People think it must be fun to be a super genius, but they don't realize how hard it is to put up with all the idiots in the world. (Calvin from Calvin And Hobbs)

Robert L. Johnson III
CCNA, CCDA, MCSA, CNA, Net+, A+
w: rljohnso@stewart.com
h: wildmage@tampabay.rr.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top