# Update-OfficeWordTableOfContents

Updates the table of contents in a Word document.

Cmdlet 

**Module**

`PSWriteOffice`

**Inputs**

`OfficeIMO.Word.WordDocument` `OfficeIMO.Word.WordTableOfContent`

**Outputs**

`OfficeIMO.Word.WordTableOfContent`

**Source**

[UpdateOfficeWordTableOfContentsCommand.cs:29](https://github.com/EvotecIT/OfficeIMO/blob/be6c300e4ab1859837b961c64fbfb2b2a1886cd0/PowerShell/PSWriteOffice/Sources/PSWriteOffice/Cmdlets/Word/UpdateOfficeWordTableOfContentsCommand.cs#L29) 

Updates the table of contents in a Word document.

## Syntax

```
Update-OfficeWordTableOfContents
[-Document <WordDocument>]
[-PassThru]
[-Regenerate]
[<CommonParameters>]
```

[#](#method-update-officewordtableofcontents-worddocument-switchparameter-switchparameter)

Parameter set: `Document`

```
Update-OfficeWordTableOfContents
[-PassThru]
[-Regenerate]
-TableOfContents <WordTableOfContent>
[<CommonParameters>]
```

[#](#method-update-officewordtableofcontents-switchparameter-switchparameter-wordtableofcontent)

Parameter set: `TableOfContents`

## Guides & Samples

Authored walkthroughs and practical samples linked to this command.

- [Add a Table of Contents and Fields in Word](/docs/word/fields-toc/) Guide
  
  Insert a table of contents, page, date and property fields into DOCX files, refresh them on open or in code, and read fields with OfficeIMO.Word.
- [Review, Protect, and Deliver Word Documents](/docs/pswriteoffice/word-review-delivery/) Guide
  
  Inspect revisions, compare Word documents, resolve approved changes, protect output, update fields, and prepare DOCX files for delivery.

## Examples

### Mark table of contents for refresh on open.

```powershell
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.

```powershell
$doc = Open-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 requiredpipeline: 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](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters).

<!-- PowerForge markdown artifact sha256:6B9A763395B8DA94C9376A1E373C6CD81AFE73C5A8C503E4FC74471E8B480EDA -->
