Appending text to an existing footer

This topic contains 1 reply, has 2 voices, and was last updated by  iain Barnetson 1 week, 6 days ago.

  • Author
  • #104029


    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"

    How can I make this append the text without losing all the footers existing formatting?

  • #104032

    iain Barnetson

    This works for me...

    $footer.Range.Text = $currentText + "`r`nCONFIDENTIAL"

You must be logged in to reply to this topic.