RE: Win32::OLE on MS Word using Selection.Find.Execute

2010-09-13 Thread Brian Raven
Peter Buck <> wrote:
>   Does anyone have an example of a perl script acting on MS Word
> documents using Win32::OLE and Selection.Find.Execute?  I have read
> the  
> Win32 man page but its examples for Excel and Access don't help.  I
> found a Powershell script that does what I want but can't translate.
> The parts I'm confused on are (1) setting the parameters used in the
> Selection.Find.Execute() invocation (particularly the boolean values,
> since perl doesn't do booleans) and the actual invocation of
> Selection.Find.Execute().  
> 
> I did find an example using $search-> Execute() but this doesn't
> appear to allow setting all the parameters that
> Selection.Find.Execute() does.  
> Also, it operates on $doc-> Content->Find while
> Selection.Find.Execute() operates on $doc->Selection (if I'm right). 
> And I'm using Homekey(6) to take me to the top of the document, which
> is linked to Selection and doesn't seem to work in my
> $doc->Content->Find attempts.
> 
> Any help or direction to documentation much appreciated.

The primary documentation for OLE apps is the Visual Basic Reference.
The OLE browser supplied with Activestate Perl is also very useful, I
find. Other than that, googling for examples can be useful, followed by
an amount of trial and error. The amount of trial and error needed will
depend on how closely the results of your googling match what you are
trying to do.

> 
> Thanks - Toolsmith
> 
> # ExpandAcronyms.ps1
> # read acronym list, expand acronyms in target MS Word document #
> syntax: ExpandAcronyms wordDocument 
> 
> function make-change {
>  $FindText = $args[0]
>  $FullText = $args[1]
>  $ReplaceText = "$FullText ($FindText)"
> 
>  $ReplaceAll = 1
>  $FindContinue = 1
>  $MatchCase = $True
>  $MatchWholeWord = $True
>  $MatchWildcards = $False
>  $MatchSoundsLike = $False
>  $MatchAllWordForms = $False
>  $Forward = $True
>  $Wrap = $FindContinue# don't want it wrapping, wish I
> knew 
> what this meant
>  $Format = $False
> 
>  $objWord.Selection.HomeKey(6) > Null
>  $result = $objSelection.Find.Execute($FindText,$MatchCase,
>  $MatchWholeWord,$MatchWildcards,$MatchSoundsLike,
>  $MatchAllWordForms,$Forward,$Wrap,$Format,
>  $ReplaceText,$ReplaceAll)
>   if ( $result -eq $true ) {
>   "$Findtext|$FullText"
>  }
> 
> }
> 
> if ( $args.count -lt 1 ) {
>  cd $env:temp
>  $strWordFile = [string](resolve-path(Read-Host "Enter Path of
>  Word file to be processed")) } else { $strWordFile =
> [string](resolve-path($args[0])) } 
> 
> 
> $objWord = New-Object -ComObject word.application
> $objWord.Visible = $True
> $objDoc = $objWord.Documents.Open($strWordFile)
> 
> $objSelection = $objWord.Selection
> 
> $d = get-content "d:/temp/acronyms.txt"# read file of acronym
> | 
> definition
> foreach ( $l in $d ) {
>  ($acro, $def) = $l.split('|')# build
> array 
> of acronym, definition
>  make-change $acro $def
> }
> "Finished"
> $objWord.Selection.HomeKey(6) > Null

That looks like shell script rather than Perl (Powershell perhaps?).
Your Perl code would have been more useful.

HTH

-- 
Brian Raven 
 
Please consider the environment before printing this e-mail.

This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient or have received this e-mail in error, please advise 
the sender immediately by reply e-mail and delete this message and any 
attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Win32::OLE on MS Word using Selection.Find.Execute

2010-09-13 Thread Mark Leighton
Peter,

OLE needs Variant values.  Perl and the OLE modules will convert most of 
these on he fly for you, but sometimes I find I have a need to convert 
booleans explicitly.

my $false = Win32::OLE::Variant->new(VT_VARIANT, 0);
my $true = Win32::OLE::Variant->new(VT_VARIANT, 1);

Mark

On 9/12/2010 4:43 PM, Peter Buck wrote:
>Does anyone have an example of a perl script acting on MS Word
> documents using Win32::OLE and Selection.Find.Execute?  I have read the
> Win32 man page but its examples for Excel and Access don't help.  I
> found a Powershell script that does what I want but can't translate.
> The parts I'm confused on are (1) setting the parameters used in the
> Selection.Find.Execute() invocation (particularly the boolean values,
> since perl doesn't do booleans) and the actual invocation of
> Selection.Find.Execute().
>
> I did find an example using $search->  Execute() but this doesn't appear
> to allow setting all the parameters that Selection.Find.Execute() does.
> Also, it operates on $doc->  Content->Find while Selection.Find.Execute()
> operates on $doc->Selection (if I'm right).  And I'm using Homekey(6) to
> take me to the top of the document, which is linked to Selection and
> doesn't seem to work in my $doc->Content->Find attempts.
>
> Any help or direction to documentation much appreciated.
>
> Thanks - Toolsmith
>
> # ExpandAcronyms.ps1
> # read acronym list, expand acronyms in target MS Word document
> # syntax: ExpandAcronyms wordDocument
>
> function make-change {
>   $FindText = $args[0]
>   $FullText = $args[1]
>   $ReplaceText = "$FullText ($FindText)"
>
>   $ReplaceAll = 1
>   $FindContinue = 1
>   $MatchCase = $True
>   $MatchWholeWord = $True
>   $MatchWildcards = $False
>   $MatchSoundsLike = $False
>   $MatchAllWordForms = $False
>   $Forward = $True
>   $Wrap = $FindContinue# don't want it wrapping, wish I knew
> what this meant
>   $Format = $False
>
>   $objWord.Selection.HomeKey(6)>  Null
>   $result = $objSelection.Find.Execute($FindText,$MatchCase,
>   $MatchWholeWord,$MatchWildcards,$MatchSoundsLike,
>   $MatchAllWordForms,$Forward,$Wrap,$Format,
>   $ReplaceText,$ReplaceAll)
>if ( $result -eq $true ) {
>"$Findtext|$FullText"
>   }
>
> }
>
> if ( $args.count -lt 1 ) {
>   cd $env:temp
>   $strWordFile = [string](resolve-path(Read-Host "Enter Path of Word
> file to be processed"))
> } else {
>   $strWordFile = [string](resolve-path($args[0]))
> }
>
>
> $objWord = New-Object -ComObject word.application
> $objWord.Visible = $True
> $objDoc = $objWord.Documents.Open($strWordFile)
>
> $objSelection = $objWord.Selection
>
> $d = get-content "d:/temp/acronyms.txt"# read file of acronym |
> definition
> foreach ( $l in $d ) {
>   ($acro, $def) = $l.split('|')# build array
> of acronym, definition
>   make-change $acro $def
> }
> "Finished"
> $objWord.Selection.HomeKey(6)>  Null
> ___
> Perl-Win32-Users mailing list
> Perl-Win32-Users@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Win32::OLE on MS Word using Selection.Find.Execute

2010-09-13 Thread Jan Dubois
On Sun, 12 Sep 2010, Peter Buck wrote:
> 
> Does anyone have an example of a perl script acting on MS Word
> documents using Win32::OLE and Selection.Find.Execute?

Actually, I do, and it is even part of the Win32::OLE module
distribution on CPAN.  But since it is not being installed
with the actual module itself it is somewhat hard to find:

http://cpansearch.perl.org/src/JDB/Win32-OLE-0.1709/eg/word2pod.pl

The script takes a Word document and tries to convert it
to POD.

Cheers,
-Jan

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs