I am trying to perform word search replace using powershell I am kind of new user of Powershell and I am using the below code which I found here in Stackoverflow while looking for a solution
$template='G:\OBS\Onboarding.docx'
$Text = "test"
$ReplaceText = "test1"
$Word = new-object -ComObject Word.Application
$template = $Word.Documents.Open($template)
$Find = $template.Content.Find
$Find.ClearFormatting()|out-null
$Find.Execute($Text, $false, $false, $false, $false, $false, $true, 1, $false, $ReplaceText, 2)
$Document.Save()
$Word.Quit()
$a=[System.Runtime.InteropServices.Marshal]::ReleaseComObject($Word)
at the moment I am getting the below error
Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH)) At G:\OBS automation\OBS-Automation.ps1:48 char:1 + $Find.Execute($Text, $false, $false, $false, $false, $false, $true, 1 ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
Can someone please help with this error ?
User contributions licensed under CC BY-SA 3.0