Hi all,

Further on this, I found I had to loop over all the Shapes in the Shapes 
collection. eg:

 use strict;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';

my $word = Win32::OLE->new('Word.Application');
$word->{visible} = 1;

my $doc = $word->{Documents}->Open("C:\\Word\\Certificate.doc");
my $count = $doc->Shapes->{Count};
for (my $i=1; $i < $count; $i++) {
        $doc->Shapes->{$i}->{TextFrame}->{TextRange}->{Text} =~ 
s/#tPreferredName#/Chris/g;
}

Surely there's an easier way? If not, it'll have to do!

Chris

----------------------------------------------
Chris Cox
B.IT.(Information Systems) 
Senior Software Engineer

Creatop Interactive Media
Level 1, 240 McCullough Street
Sunnybank. Qld. 4109
Australia
Ph:      1300 85 80 85
Int'l Ph:     +61 7 3216 9755
Mobile: +61 412 416600
http://www.creatop.com.au/
[EMAIL PROTECTED]
----------------------------------------------

----- Original Message ----- 
From: [EMAIL PROTECTED]
To: [email protected]
Sent: 
Subject: Microsoft Word search and replace issue Hi all,

Firstly, I hope sending an attachment is allowed. I figure it'll be easier to 
provide a real example of my problem.

Anyway, I'm trying to write a basic perl script to open a Word document, change 
some predefined values to something else.

It works fine on a basic document, but anything with text boxes it doesn't work 
at all.

The script I run is:

use strict;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Word';

my $word = Win32::OLE->new('Word.Application');
$word->{visible} = 1;
my $doc = $word->{Documents}->Open("C:WordCertificate.doc");

my $search =  $doc->Content->Find;
my $replace = $search->Replacement;
$search->{Wrap} = wdFindContinue;
$search->{Text} = "#tPreferredName#";
$replace->{Text} = "Chris";
$search->Execute({Replace => wdReplaceAll});

$doc->SaveAs("C:WordCertificate_changed.doc");

I've attached a ZIP file with the code, and 2 different styles of Word 
Documents. One, a basic one with hardly anything, and 2 the actual document we 
need to work with.

Any help would be appreciated, I'm new at this!

Cheers,

Chris

----------------------------------------------
Chris Cox
B.IT.(Information Systems) 
Senior Software Engineer

Creatop Interactive Media
Level 1, 240 McCullough Street
Sunnybank. Qld. 4109
Australia
Ph:      1300 85 80 85
Int'l Ph:     +61 7 3216 9755
Mobile: +61 412 416600
http://www.creatop.com.au/
[EMAIL PROTECTED]
---------------------------------------------- 
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to