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
    Posts
  • #104029

    Dave
    Participant

    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

    iain Barnetson
    Participant

    This works for me...

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

You must be logged in to reply to this topic.