Open Doc file
kanish
created: 2006-01-05 00:45:57

Dear Monks,

I want to open a doc file and find some thing and replace something. And also add Template.

I know those above works doing Win32::OLE but i am not familiar with that module.

Could you please give link, it would be very help to further.

Thanks a lot!!

Kanishk

Re: Open Doc file
created: 2006-01-05 01:26:02

Hi, this can help you...

use OLE;
use Win32::OLE::Const 'Microsoft Word';
my $const = Win32::OLE::Const->Load("Microsoft Word 9.0 Object Library"); # 9.0 for word2000, 11.0 for word2003 or XP

$word=GetObject OLE("Word.Application");      ### To access the active Word Document

$word->Selection->HomeKey ({unit=>$const->{'wdStory'}});

&WordReplaceAll('find', 'replace');

sub WordReplaceAll
{
    my($FindText,$ReplaceText)=@_;
    for ($word->Selection->Find)
    {
        $_->{'Text'} = $FindText;
        $_->Replacement->{'Text'} = $ReplaceText;
        $_->Execute ({Replace=>$const->{'wdReplaceAll'}});
    }
}

regards,
Franklin

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

perlmonks.org content © perlmonks.org and kanish, l.frankline

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03