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

 
Participant
3 months, 2 weeks ago.

  • Author
    Posts
  • #104029

    Participant
    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"
    }
    $document.Save()
    $document.Close()
    $word.Quit()

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

  • #104032

    Participant
    Points: 3
    Rank: Member

    This works for me...

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

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