Sang has asked for the wisdom of the Perl Monks concerning the following question:

The title and code fragment sum it up pretty well. Using the code below I run into the problem that the script is trying to close Word while the document is still being sent to the printer.

The quick fix for testing was to just throw in a 'sleep 5' after the PrintOut command, obviously not the best solution. Is anyone familiar with a way to actually check if the file has finished being sent to the printer? I've checked a bunch of nodes and OLE docs but appear to be missing the fix...

my $Word = Win32::OLE->new('Word.Application', 'Quit'); $Word->{'Visible'} = 1; $Word->Documents->Add; # ... Excel Chart, as GIF, inserted ... $Word->ActiveDocument->PrintOut; # sleep( 5 ); $Word->ActiveDocument->{Saved} = 1;

Replies are listed 'Best First'.
Re: Win32::OLE - Wait until print job is queued?
by jlongino (Parson) on Jan 13, 2002 at 12:34 UTC
    I don't know if this will help or not, but a quick Super Search turned up this node which contains many and varied solutions.

    --Jim

Re: Win32::OLE - Wait until print job is queued?
by guha (Priest) on Jan 13, 2002 at 21:34 UTC
    You could try this, **NOTE** not tested by me.

    I would suspect that this makes the printing/spooling in the foreground, hence control will be returned to your app as soon as it's ready.

    $Word->ActiveDocument->PrintOut({Background => 0});
    or possibly
    $Word->ActiveDocument->PrintOut(0);

    HTH

    ---
    It's unfair to be an expert.