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
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs