Ms-Word Ole and multiple independent instances.

R

Rudy Van Eeckhout

Hello all,

I do have several perl scrips whicht opens by ole an word instance
which is used to print a document to a certain printer. Now we noted
that these documents sometimes appear on the wrong printer. After some
investiation is did seen next effect.
First assume next script

my $Word= Win32::OLE->CreateObject('Word.Application', 'Quit');
$openWord->{'Visible'} = 0;
$Word->{ActivePrinter} = "$printer";
<STDIN> ; #Wait for a cariage return
print $Word->{ActivePrinter} ."\n" ;

When i run this script with $printer set to printerA and i do wait to
give a cariage return until i did run the script in a second form with
$printer set to printerB. The both script will print as active printer
printerB. This means that the assingment of Activeprinter is done for
all instances which are running.

Even when you try this manualy by opening 2 word sessions you can see
that the printer changes over the different sessions.

If you start msword from the command line with the /w option the
problem disapears.
Now i can not find out how to do this over perl OLE.

Is there anybody who knows how to sole this over OLE?

Kind regards.

Rudy.
 
D

Dave

Rudy Van Eeckhout said:
Hello all,

I do have several perl scrips whicht opens by ole an word instance
which is used to print a document to a certain printer. Now we noted
that these documents sometimes appear on the wrong printer. After some
investiation is did seen next effect.
First assume next script

my $Word= Win32::OLE->CreateObject('Word.Application', 'Quit');
$openWord->{'Visible'} = 0;
$Word->{ActivePrinter} = "$printer";
<STDIN> ; #Wait for a cariage return
print $Word->{ActivePrinter} ."\n" ;

When i run this script with $printer set to printerA and i do wait to
give a cariage return until i did run the script in a second form with
$printer set to printerB. The both script will print as active printer
printerB. This means that the assingment of Activeprinter is done for
all instances which are running.

Even when you try this manualy by opening 2 word sessions you can see
that the printer changes over the different sessions.

If you start msword from the command line with the /w option the
problem disapears.
Now i can not find out how to do this over perl OLE.

Is there anybody who knows how to sole this over OLE?

Kind regards.

Rudy.

I think this is more of a Word issue than a perl issue, and I suspect
(without looking into it) that activeprinter is a global setting for word
rather than a per-document setting.

In the example script you give you set the activeprinter early, then wait
for input and then print to it. If instead you set the activeprinter just
before printing you would have fewer problems. You might still get the odd
glitch if two scripts are running concurrently and both try to change the
setting at nearly the same time, but this would happen far less often than
the current issue which is that you set the printer, wait (during which time
another process may set it to something else) and then print.

Dave
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top