Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Open-OfficeWord

Module
PSWriteOffice
Inputs
System.String
Outputs
OfficeIMO.Word.WordDocument System.IO.FileInfo

Opens a Word document for explicit editing, or saves and closes a completed content block.

Syntax

Open-OfficeWord
[-AllowLoss]
[[-Content] <ScriptBlock>]
[-PassThru]
[-Password <SecureString>]
[-Path] <String>
[-ReadOnly]
[-Show]
[<CommonParameters>]
#
Parameter set: Path
Open-OfficeWord
[-AllowLoss]
[[-Content] <ScriptBlock>]
-LiteralPath <String>
[-PassThru]
[-Password <SecureString>]
[-ReadOnly]
[-Show]
[<CommonParameters>]
#
Parameter set: LiteralPath

Description

Opening preserves the document's theme and encryption. Without a block the document remains live. A failed block leaves the source unchanged; read-only input cannot run an authoring block.

Examples

Open a literal file path from a file pipeline.

$document = Get-Item './Review[final].docx' | Open-OfficeWord
$document | Close-OfficeWord

Edit and save an existing document atomically.

Open-OfficeWord -Path ./Report.docx -PassThru {
    WordParagraph 'Reviewed and approved'
}

Parameters

-AllowLoss SwitchParameter optional
Gets or sets whether native-save loss is explicitly accepted.
-Content ScriptBlock optionalposition: 1
Gets or sets a content block; omission returns the live document.
-PassThru SwitchParameter optional
Gets or sets whether a completed content block returns the saved FileInfo.
-Password SecureString optional
Source password as a SecureString, credential, or warned plaintext value.
-Path String requiredposition: 0pipeline: True (ByValue)sets: Path
Word document path with FileSystem wildcard expansion.
-ReadOnly SwitchParameter optional
Return a read-only live document. Cannot be combined with Content.
-Show SwitchParameter optional
Gets or sets whether the saved file opens in the system default application.
-LiteralPath String requiredpipeline: True (ByPropertyName)aliases: FullName, PSPathsets: LiteralPath
Word document path without wildcard expansion; accepts FileInfo.FullName and provider PSPath.

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.