Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Update-OfficeWordText

Aliases: Replace-OfficeWordText
Module PSWriteOffice
Aliases
Replace-OfficeWordText
Inputs
OfficeIMO.Word.WordDocument
Outputs
System.Int32

Replaces text in a Word document.

Syntax

Update-OfficeWordText [-CaseSensitive] [-IncludeHyperlinkAnchor] [-IncludeHyperlinkText] [-IncludeHyperlinkTooltip] [-IncludeHyperlinkUri] -NewValue <String> -OldValue <String> [-PassThru] [<CommonParameters>]
#
Parameter set: Auto
Update-OfficeWordText [-CaseSensitive] [-Document <WordDocument>] [-IncludeHyperlinkAnchor] [-IncludeHyperlinkText] [-IncludeHyperlinkTooltip] [-IncludeHyperlinkUri] -NewValue <String> -OldValue <String> [-PassThru] [<CommonParameters>]
#
Parameter set: Document
Update-OfficeWordText [-CaseSensitive] [-IncludeHyperlinkAnchor] [-IncludeHyperlinkText] [-IncludeHyperlinkTooltip] [-IncludeHyperlinkUri] -NewValue <String> -OldValue <String> [-Open] [-PassThru] [-Path] <String> [<CommonParameters>]
#
Parameter set: Path

Description

Supports direct document objects, file paths, and the active DSL document. Hyperlink labels and metadata can be updated when requested.

Examples

Authored help example

Replace text in an open document.

$count = $doc | Update-OfficeWordText -OldValue 'FY24' -NewValue 'FY25' -PassThru

Updates matching text in the loaded document and returns the number of replacements.

Replace hyperlink targets in a file.

Update-OfficeWordText -Path .\Report.docx -OldValue 'old.example.com' -NewValue 'new.example.com' -IncludeHyperlinkUri

Loads the document, updates matching hyperlink URLs, saves the file, and closes it.

Parameters

-CaseSensitive SwitchParameter optional
Use case-sensitive matching.
-IncludeHyperlinkAnchor SwitchParameter optional
Also replace hyperlink anchors.
-IncludeHyperlinkText SwitchParameter optional
Also replace hyperlink display text.
-IncludeHyperlinkTooltip SwitchParameter optional
Also replace hyperlink tooltips.
-IncludeHyperlinkUri SwitchParameter optional
Also replace hyperlink URIs.
-NewValue String required
Replacement text.
-OldValue String required
Text to find.
-PassThru SwitchParameter optional
Emit the object created or changed by the command.
-Document WordDocument optionalpipeline: True (ByValue)sets: Document
Document to update.
-Open SwitchParameter optionalaliases: Showsets: Path
Open the file after saving when using -Path.
-Path String requiredposition: 0aliases: FilePath, InputPathsets: Path
Path to the .docx file to update in place.

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.