Closing Document Removing Icon

kirkm

Registered User.
Local time
Tomorrow, 02:30
Joined
Oct 30, 2008
Messages
1,257
Hi,
This is rather hard to explain as I don't really know what I'm doing.
I've a macro in Word 2002 which reads through about 200 html docs and outputs various parts of them to a text file.
As each one is processed a new Word Icon appears in the Task Manager and I can't get rid of it, except manually. Can it be removed progamicably?

The actual doc files closes OK, just that the Icons stay put.
Thanks - Kirk
 
I expect you are not quiting the instance of Word that is opened by you code, although it is not clear from your post that you are using Word to read or write the files. This code snippet may help;

Set myWordApp = CreateObject("Word.Application")
...process your files
myWordApp.Quit
 
Hi Cameron,
If I knew how to apply or use that code snippet, yes it might. The code is in Word. After I have the filename as sDoc, it runs this -

--
Sub OpenDoc(sDoc As String)
Dim OpenWord As Word.Application
Set OpenWord = New Word.Application
Dim D As Document
Dim ff, ar, ti, j$
Dim LastLine%, i%, pa
Dim R As Range
With OpenWord
.Visible = True
.Documents.Open sDoc, , True
j$ = "~"
ff = FreeFile
Set D = .ActiveDocument
LastLine = D.Paragraphs.Count
Open "O:\MyData\Output\results.txt" For Append As #ff
For i = 1 To LastLine

DoEvents
Set R = D.Paragraphs(i).Range

pa = R.Words(1).Bold & R.Words(1).Italic & R.ParagraphFormat.LeftIndent

Select Case pa
' Do stuff and print#ff
End Select

Next

Close #ff
D.Close SaveChanges:=wdDoNotSaveChanges
Set R = Nothing
Set D = Nothing

End With
Set OpenWord = Nothing
End Sub
--

There may be many errors - but it sort of does what I want.
I've tried a number of alternatives to the D.Close line but nothing seems to remove the task bar icon.

Can you see what/where this could be changed to achieve that - or where I'd put your Create Object part?

Thanks - Kirk
 
In your code "OpenWord" is an object representing an New instance of Word. You are currently opening Word then performing your operation, but you are not closing Word, which is why the icon continues to be displayed in task manager.

You need to add:

OpenWord.Close [depending on your version of Word there may be an no-save option]

before to code:
Set OpenWord = Nothing (FYI: I don't even know if this line does anything, but since I guess you got it from some other post leave it in).
 
Sorry, no go. Openword. has no Close option. If I type in anyway I get
'Method or data member not found'.
Do you have anything else to try?
Thanks - Kirk
 
What version of Word are you using? Does OpenWord have a Quit method?
You definately need to close/quit the current Word.Application instance to get rid of the icon.
 

Users who are viewing this thread

Back
Top Bottom