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

Hi Monks,

I can able to open a doc file and find the text.

Problem is how to replace it.

use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Word'; my $word = Win32::OLE->new('Word.Application'); $word->{Visible} = 1; my $document=$word->Documents->Open('c:/temp/test.doc'); $word->Selection->HomeKey(wdStory); $word->Selection->Find->{'Text'}='Some Text'; $word->Selection->Find->Replacement->{'Text'}='Replaced Text'; $word->Selection->Find->Execute(); ### Need help here

Thanks,

Kanishk

Replies are listed 'Best First'.
Re: Replace word in Win32::OLE
by l.frankline (Hermit) on Jan 06, 2006 at 07:04 UTC

    Hi,

    Modify your code as given below

    $word->Selection->Find->Execute();

    should be

    $word->Selection->Find->Execute({Replace=>$const->{'wdReplaceAll'}}); + #replace whole file $word->Selection->Find->Execute({Replace=>$const->{'wdReplaceOne'}}); + #replace one by one

    for more information see replace

    regards,
    Franklin

    Don't put off till tomorrow, what you can do today.

Re: Replace word in Win32::OLE
by gopalr (Priest) on Jan 06, 2006 at 07:21 UTC

    Hi Kanishk

    Changed your code

    $word->Selection->Find->Execute({Replace=>wdReplaceAll});

    Thanks
    Gopal R.

Re: Replace word in Win32::OLE
by gube (Parson) on Jan 06, 2006 at 07:24 UTC
    $word->Selection->Find->Execute({Replace=>wdReplaceAll});
    or for Single Word $word->Selection->Find->Execute({Replace=>wdReplaceOne});
Re: Replace word in Win32::OLE
by Anonymous Monk on Jan 06, 2006 at 10:55 UTC
    I see some replies that are right to the point of the question.
    I was looking at Win32::OLE a while ago myself and found it really hard to find the correct calls and syntax for a given task.
    Can anybody point me to a good resource for finding information about how to construct the calls to Win32::OLE "functions"?
    Thanks