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

Dear Monks, I am a beginner with OOP. I want to open a microsoft word document, find a phrase and then replace it with another phrase. Here is what I come up with so far,
#!/usr/bin/perl
use strict;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';
use Win32::OLE::Const 'Microsoft Office';
my $word = Win32::OLE->new('Word.Application', 'Quit'); $word->Documents->Open("S:\\Documents\\TOWNSHIP FORECASTS\\TEST.doc") || die("Unable to open document ", Win32::OLE->LastError());
my $selection = $word->Selection;
$selection->Find;
$selection->{Text} = "CENTRAL NJ";
$selection->Replacement;
$selection->{Text} = "South River DPW";
$selection->wdReplaceALL;
$word->ActiveDocument->Save;
What's happening is it keeps adding South River DPW to the document and keeping CENTRAL NJ. Any info will be greatly appreaciated. Thanks

Replies are listed 'Best First'.
Re: Wind32::OLE and Microsoft Word
by marto (Cardinal) on Jul 24, 2007 at 08:17 UTC
      but beware that the OLE interface you are using may change at any time, MS has a habit of breaking such things when creating new versions.

      just another cpan module author
      Thank you for your help.