# If Word is already running, then use the existing instance,
# and leave it running when we are done.
# Otherwise, start a new instance of Word, and close it when
# we are done.
use strict;
use warnings;
use Win32::OLE;
my $Word;
eval {$Word = Win32::OLE->GetActiveObject('Word.Application')};
die "Word not installed: $@" if $@;
unless (defined $Word) {
$Word = Win32::OLE->new('Word.Application', sub {$_[0]->Quit})
or die "Oops, cannot start Word";
}
$Word->{'Visible'} = 1; # If you want to see what's going on
|