"Phantom" window

E

edger

I have a VBScript script that processes text files into both Word and Excel
documents. The script runs macros that I have written in a document and
workbook called WordMacros.doc and ExcelMacros.xls. The script reads
instructions from text files, opens the document or workbook as required, and
runs the appropriate macro to do the processing.

This works fine, but at the conclusion of the processing, an extraneous
(empty)Word window opens. I've tried all sequences of opening and closing
Word that I can think of, but nothing seems to prevent this.

Set appWord = CreateObject("Word.Application")
appWord.Visible = False
appWord.Documents.Open(WordMacros)
...
...
appWord.Documents.Close()

Doing the Open and Close just once each doesn't work and neither does doing
them before and after each macro. I've tried closing and not closing the
newly-created document within each macro.

Any ideas???
 
T

Tony Jollans

Hi Edger,

As well as closing the document, you need to quit the application and, as
good practice if nothing else, release the object variable ...

Set appWord = CreateObject("Word.Application")
appWord.Visible = False
appWord.Documents.Open(WordMacros)
...
...
appWord.Documents.Close()
appWord.Quit
Set appWord = Nothing
 
E

edger

Bless you, sir. That was driving me up the wall. Interestingly, a comparable
command is apparently unnecessary for Excel.
Edger
 
T

Tony Jollans

Glad I could help.

You really should do exactly the same in Excel. At the very least it's good
practice. Even if what you have appears to be working at the moment (which
surprises me) it'll come back to haunt you sooner or later.
 
E

edger

Thanks, I'll add that to my script . It already releases both object
variables.
edger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top