JRB
JRB said:
I'll haven't tried your suggestion yet but I am using Acrobat Distiller as
the printer and it does produce the requisite number of pages (89 pages) and
completes the printing in approx 8 seconds.
What I have noticed is:
After the first (successful) run I looked in TaskManager to see if Word was
still running ... It wasn't
After the second (unsuccessful) run when the procedure fails with the
Automation Error I open Task Manger and not surprisingly Winword is running.
But if I then end the Winword application using TaskManager .... the
procedure will then work next time around
It's probably not the Word application, but the Word document that's
remaining open. So you won't see the Word app in task manager, but it's
really still open behind the scenes. You don't have any problem with the
CreateObject line because it's not using the same instance of Word, but when
you try to access the ActiveDocument, that's where it runs into a conflict.
When my head stops spinning I will try your suggestion about adding a time
delay of 10 secs before killing the object.
Klunky or not I need to find a solution.
Is there a way to pause execution until the print process is completed ?
Other that a Do..Loop like I've described, I don't know of any way. It's
not so much when the printing is completed, but when it starts. (This may
not really apply using Distiller compred to a normal spooled printer.) I
can close a Word document once IT'S done printing, but before the printer is
done. Once the print job is sent, Word and the document can be closed, even
if the print spooler is still working. That makes me think that Word isn't
done sending information to Distiller. Which makes sense, because your
procedure ends about a microsecond after it starts, which is hardly enough
time for Word to do its thing.
The point is, you don't have to pause the macro until printing is done
(probably), just until Word has finished sending its info to Distiller. It
won't hurt to pause it that long, using a Do..Loop, particularly while
you're testing. But before you go final with it, you might experiment with
shorter pause times so you don't have to wait so long.
I wonder if you can hook into that Word document at the start of your sub
and kill it. Untested, but something like this
Dim wdAppCleanUp as Object
Dim wdDocCleanUp as Object
On Error Resume Next
Set wdDocCleanUp = GetObject(,"PrivList Labels.doc")
Set wdAppCleanUp = wdDoc.Parent
wdDocCleanUp.Close
wdAppCleanUp.Quit
On Error Goto 0
'Rest of your code here
So before you ever run the mailmerge stuff, you try to hook into that
orphaned instance of the Word doc and clean it up (it should be done by the
next time you run the sub). I don't know if you can use GetObject in that
manner, but it might be worth a try if you get desperate. The On Error will
prevent an problems on the first run or if the document isn't orphaned for
some reason.