Using Win32::OLE Part II
Manning, Rob
Rob_Manning at mail.ci.baltimore.md.us
Wed Dec 8 07:56:00 CST 1999
One additional point I'd like to make about the
script that I sent out this morning is that it fails to call
$WordObj->exit;
at the end thereby removing the active instance of
Word from the environment when the script finishes.
Another tip is when placing the script code inside of a loop
be careful to create the Word object only once before the
loop is entered and use it to open and close documents
inside the loop. Tremendous memory usage will result
if you create a hundred or so simultaneous Word instances
without exiting them (i.e. Ctrl-Alt-Del may be your only hope!)
Bad:
for $file (@file_list) {
$WordObj = Win32::OLE->new('Word.Application', 'Quit');
$wd = $WordObj->Documents->Open($file);
$WordObj->ActiveDocument->SaveAs({
FileName => $new_file,
FileFormat =>wdFormatText,
});
$wd->Close();
}
Better:
for $file (@file_list) {
$WordObj = Win32::OLE->new('Word.Application', 'Quit');
$wd = $WordObj->Documents->Open($file);
$WordObj->ActiveDocument->SaveAs({
FileName => $new_file,
FileFormat =>wdFormatText,
});
$wd->Close();
$WordObj->exit;
}
Most efficient:
$WordObj = Win32::OLE->new('Word.Application', 'Quit');
for $file (@file_list) {
$wd = $WordObj->Documents->Open($file);
$WordObj->ActiveDocument->SaveAs({
FileName => $new_file,
FileFormat =>wdFormatText,
});
$wd->Close();
}
$WordObj->exit;
Rob
Rob Manning manningr at tcsnet.net
Senior Systems Analyst Work (410) 396-4963
TeleCommunication Systems Fax (410) 837-0546
--
Looking for a Perl user's group in Baltimore? - http://baltimore.pm.org
More information about the Baltimore-pm
mailing list