Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Update-OfficeWordTableOfContents

Module PSWriteOffice
Inputs
OfficeIMO.Word.WordDocument OfficeIMO.Word.WordTableOfContent
Outputs
OfficeIMO.Word.WordTableOfContent

Updates the table of contents in a Word document.

Syntax

Update-OfficeWordTableOfContents [-Document <WordDocument>] [-PassThru] [-Regenerate] [<CommonParameters>]
#
Parameter set: Document
Update-OfficeWordTableOfContents [-PassThru] [-Regenerate] [-TableOfContents <WordTableOfContent>] [<CommonParameters>]
#
Parameter set: TableOfContents

Examples

Authored help example

Mark table of contents for refresh on open.

New-OfficeWord -Path .\ExecutiveReport.docx {
    Add-OfficeWordTableOfContents
    Add-OfficeWordParagraph -Text 'Executive summary' -Style Heading1
    Add-OfficeWordParagraph -Text 'Summary text'
    Update-OfficeWordTableOfContents
}

Marks TOC fields as dirty and updates the document settings so Word refreshes the TOC when opened.

Regenerate a TOC in an existing document object.

$doc = Get-OfficeWord -Path .\Report.docx
$doc | Update-OfficeWordTableOfContents -Regenerate
$doc | Save-OfficeWord -Path .\Report-RegeneratedToc.docx

Uses OfficeIMO's regenerate path, then saves the updated document.

Parameters

-Document WordDocument optionalpipeline: True (ByValue)sets: Document
Document to update when provided explicitly.
-PassThru SwitchParameter optional
Emit the updated table of contents.
-Regenerate SwitchParameter optional
Rebuild the table of contents before updating.
-TableOfContents WordTableOfContent optionalpipeline: True (ByValue)sets: TableOfContents
Table of contents to update.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.