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: Search and replace in msword .doc
by other posts by this author
Jan 28 2003 7:32PM messages near this date
view in the new Beta List Site
Search and replace in msword .doc | RE: socket application
Use 'or die Win32::OLE-> LastError();' to see what the error is.  In this
case it was 'Type mismatch' on the line with Ecexute.  Then look in the
Visual Basic Object Browser (in Word, under the tools-> maco menu is the
Visual Basic Editor, you use this to look at macros that you want to do in
perl, in the VBE under the View menu is the Object Browser).  Here you can
see that 'Const wdReplaceAll = 2'.  So, replace wdReplaceAll with 2.

-- 
Nathaniel G. Bartusiak
TTMS, Keesler AFB


>  Greetings to all,
> 
>  i want to do some 'find and replace' on a .doc file.
>  Sample i found on this mailing list was:
> 
>  -----------------
>  use strict;
>  use Win32::OLE;
>  use Win32::OLE::Const;
> 
> 
>  my $wd = Win32::OLE::Const->Load("Microsoft Word 9.0 Object Library");
>  my($outputFile) = 'file.doc';
>  my($word) = Win32::OLE -> new('Word.Application', 'Quit');
>  $word -> {Visible} = 1;  # Watch what happens
>  my($doc) = $word -> Documents -> Open("/perl2exe5.03/wind_spl/ml1.doc");
>   my $search = $doc->Content->Find;
>  my $replace = $search->Replacement;
> 
>  $search->{Text} = "searched";
>  $replace->{Text} = "replace";
>  $search->Execute({Replace => wdReplaceAll});
> 
>  $doc -> Close();
>  $word -> Quit();
> 
>  -----------------
> 
> 
> 
>  But it does not work: replacement does not happen.
>  What is wrong in this code?
>  Thanks for any answer.
> 
>  Philippe Paclet
> 
>  _______________________________________________
>  Perl-Win32-Users mailing list
>  Perl-Win32-Users@[...].com
>  To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Philippe Paclet


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