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

I already had codes that open an Office Words document and do some process :
my $Word = Win32::OLE->new('Word.Application'); my $Doc = $Word->Documents->Open($worktemplate); $Doc->ActiveWindow->Selection->InsertFile($worktxtfile); $Doc->ActiveWindow->Selection->HomeKey(wdStory); $Doc->ActiveWindow->Selection->WholeStory; $Doc->ActiveWindow->Selection->Font->{'Size'}='9'; $Doc->ActiveWindow->Selection->Font->{'Name'}='Courier New';
Now, I want to do a Find (search the word "EOP" in the document) and insert a page break, can anyone help me, many thanks. sungy

Replies are listed 'Best First'.
Re: MS Office Words Question
by vkon (Curate) on Jun 06, 2006 at 16:08 UTC
    Here is my excerpt from my working script, use at your will.
    my $forward = ($backward?$f:$t); my $r0 = $doc->Range({Start=>$rs,End=>$re}); my $find_r = $r0->Find; $find_r->ClearFormatting; $find_r->{Style} = $style; $find_r->Execute({FindText=>$text,MatchWildcards=>$f,Forward=>$forwa +rd,Wrap=>$wconst->{wdFindStop}}); if ((!$find_r->Found) || $r0->{Start}>=$re || $r0->{End}<=$rs) { return @r; }
    $f and $t are constants, and $wconst->{...} is too...

    BTW it isn't fastest approach to always call $Doc->ActiveWindow->Selection->...., place that in a variable!

Re: MS Office Words Question
by planetscape (Chancellor) on Jun 06, 2006 at 17:56 UTC