Because of GDPR, the company I work for needs to append “CONFIDENTIAL” to the end of every document. I’ve written a powershell script to append text to the footer but when it runs, the existing footer loses its formatting. Here’s my code(only for one document at the minute):
$word = New-Object -ComObject Word.Application $word.Visible = $false $document = $word.Documents.Open("C:\temp\Doc1.docx") foreach ($section in $document.Sections) { $footer = $section.Footers.Item(1) $currentText = $footer.Range.Text $footer.Range.Text = $currentText + "CONFIDENTIAL" } $document.Save() $document.Close() $word.Quit()
How can I make this append the text without losing all the footers existing formatting?