Is there a good way to perform an insert of text into the middle of an existing Word document using PowerShell? It appears straightforward to open from a template:
$TemplatePath = "C:\Template.dotx"
$SavePath = "C:\Saved.docx"
$Word = New-Object -ComObject "Word.Application"
$Doc = $Word.Documents.Add( $TemplatePath )
$Selection = $Word.Selection
$Range = $Doc.Content
At that point, it's unclear if we should insert string "tags" and perform a $Selection.Find.Execute()
to the tag, or if there's a better way to seek into the document and then write the new content from that point onward. I've tried a few methods, but $Selection.Find.Execute()
doesn't insert at the location found, and $Range
doesn't have a TypeParagraph()
method.
Is there a standardized way to do this?