Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/
Cmdlet

Close-OfficeWord

Module
PSWriteOffice
Inputs
OfficeIMO.Word.WordDocument

Closes one or more tracked Word documents, optionally saving them.

Syntax

Close-OfficeWord
[-AllowLoss]
[-Password <SecureString>]
[-Path <String>]
[-Save]
[-Show]
[<CommonParameters>]
#
Parameter set: Current
Close-OfficeWord
[-AllowLoss]
[-Document] <WordDocument>
[-Password <SecureString>]
[-Path <String>]
[-Save]
[-Show]
[<CommonParameters>]
#
Parameter set: Document
Close-OfficeWord
-All
[-AllowLoss]
[-Password <SecureString>]
[-Save]
[-Show]
[<CommonParameters>]
#
Parameter set: All

Description

Provides a cmdlet wrapper for WordDocument.Dispose/Save so scripts need not call .NET methods directly. Documents must use explicit persistence to prevent writes during disposal.

Examples

Close without saving.

$doc = Open-OfficeWord -Path .\Report.docx; Close-OfficeWord -Document $doc

Disposes the loaded document instance without saving changes.

Close the most recently tracked document.

Close-OfficeWord

Closes the current tracked document when a document handle is not passed explicitly.

Save to a new path and open the file.

Close-OfficeWord -Document $doc -Save -Path .\Report-final.docx -Show

Saves updates to Report-final.docx, opens it, and disposes the document.

Parameters

-AllowLoss SwitchParameter optional
Explicitly accept reported native-save reductions.
-Password SecureString optional
Password used to save the document as an encrypted package.
-Path String optionalsets: Current, Document
Optional target path when saving.
-Save SwitchParameter optional
Persist changes before closing.
-Show SwitchParameter optional
Open the file after saving. Requires -Save or -Path.
-Document WordDocument requiredposition: 0pipeline: True (ByValue)sets: Document
Word document to close.
-All SwitchParameter requiredsets: All
Close all tracked documents for the current runspace.

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.