Appending text to an existing footer

Welcome Forums General PowerShell Q&A Appending text to an existing footer

This topic contains 1 reply, has 2 voices, and was last updated by

1 year, 1 month ago.

  • Author
  • #104029

    Topics: 1
    Replies: 0
    Points: 0
    Rank: Member

    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

    Topics: 36
    Replies: 149
    Points: 437
    Helping Hand
    Rank: Contributor

    This works for me...

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

The topic ‘Appending text to an existing footer’ is closed to new replies.