toolsmith has asked for the wisdom of the Perl Monks concerning the following question:

Need help translating this powershell ole MS Word script to perl. I've scoured the web for the answer, you're my only hope. I'm especially interested in how boolean values are handled, and in the invocation of Selection.Find.Execute(). I know this might be more of a Word question (or a Win32::OLE question) than a perl question. I've tried to find the answer everywhere I can think of before coming to the Monks. Thanks - Toolsmith
$comments = @' Script name: Replace-WordText.ps1 Created on: Tuesday, April 03, 2007 Author: Kent Finkle Purpose: How can I use Windows Powershell to Find and Replace Text in +a Microsoft Word Document? '@ $objWord = New-Object -comobject Word.Application $objWord.Visible = $True $objDoc = $objWord.Documents.Open("C:\Scripts\Test.doc") $objSelection = $objWord.Selection $FindText = "Contoso" $MatchCase = $False $MatchWholeWord = $False $MatchWildcards = $False $MatchSoundsLike = $False $MatchAllWordForms = $False $Forward = $True $Wrap = $wdFindContinue $Format = $False $wdReplaceNone = 0 $ReplaceWith = "" $wdFindContinue = 1 $a = $objSelection.Find.Execute($FindText,$MatchCase,$MatchWholeWord, +` $MatchWildcards,$MatchSoundsLike,$MatchAllWordForms,$Forward,` $Wrap,$Format,$ReplaceWith,$wdReplaceNone) If ($objSelection.Find.Found) { Write-Host("The search text was found.") } Else { Write-Host("The search text was not found.") }

Replies are listed 'Best First'.
Re: MS Word OLE help
by Anonymous Monk on Sep 12, 2010 at 18:27 UTC
Re: MS Word OLE help
by ww (Archbishop) on Sep 12, 2010 at 17:14 UTC

    Then study Perl...
    and then try to do the conversion (i.e., write some Perl); test, repeat as necessary, and...
    come back here only when you have a question that's tantamount to something other than "please do it for me, for free."

    See On asking for help and How do I post a question effectively?. We really do offer help; but that stops short of 'free-coding.'

    By the way, there's what appears to be a factual error in your node.
    "you're my only hope."

    Not so; there's always the conventional route of hiring a programmer.

      I have been writing perl for years. And I'm not asking for you to write my script. All I want is an example of a script using Win32::OLE accessing MS Word with Selection.Find.Execute. Or some documentation that specifically mentions that interface. I've been thru the Win32 documentation on CPAN, which is rich in examples for Excel and Access--but not Word. And I studied the earlier article Help using Win32::OLE to add Excel charts having multiple series (mentioned below) but that doesn't address Selection.Find.Execute.
Re: MS Word OLE help
by planetscape (Chancellor) on Sep 12, 2010 at 23:26 UTC