ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl-win32-users
perl-win32-users
RE: Microsoft Word search and replace issue
by Jan Dubois other posts by this author
May 19 2005 11:05PM messages near this date
view in the new Beta List Site
RE: Microsoft Word search and replace issue | Re: Microsoft Word search and replace issue
On Thu, 19 May 2005, Chris Cox wrote:
>  Further on this, I found I had to loop over all the Shapes in the Shapes collection. eg:
>  
>   use strict;
>  use Win32::OLE;

You could try:

  use Win32::OLE qw(in);

>  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");

and then

  foreach my $shape (in $doc-> Shapes) {
      $shape-> {TextFrame}->{TextRange}->{Text} =~ s/#tPreferredName#/Chris/g;
  }

instead of

>  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!

I'm not sure if it is that much easier.  It certainly looks nicer,
but note that I have no idea if it actually works. :)

Cheers,
-Jan



_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Chris Cox
Jan Dubois
Greg Chapman

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved