I need to count the number of characters in a word document including the characters in the headers and footers. I can successfully count the number of chars in the main document, thanks to the help I got here : Powershell How to get character count at word document? but I have not succeeded in finding how to get to the headers and footers. Any ideas ? Thanks a lot in advance for any help.
EDIT :
following code loops through the headers and footers of a word document but I can not seem to be able to get their sizes.
Add-Type -AssemblyName System.Windows.Forms
$browser = New-Object System.Windows.Forms.FolderBrowserDialog
$null = $browser.ShowDialog()
$path = $browser.SelectedPath
Get-ChildItem $path -Recurse -File |
Foreach-Object {
$Word = New-Object -comobject Word.Application
$filename = $_.FullName
$Word.Visible = $False
$datasheet = $word.Documents.Open($filename,$false, $true)
$Word.ActiveDocument.Content.Select()
foreach ($section in $datasheet.Sections)
{
ForEach ($header in $section.Headers)
{
#$header.Range.Fields.Update() | Out-Null
$NbHeader = $header.Range.Text.Count.ToString()
"header $NbHeader"
}
ForEach ($footer in $section.Footers)
{
#$footer.Range.Fields.Update() | Out-Null
$NbFooter = $footer.Range.Text.Count.ToString()
"footer $NbFooter"
}
}
$datasheet.close()
$word.Quit()
}
Read-Host -Prompt "Press Enter to exit"