Project

PSWriteOffice

PowerShell document automation across OfficeIMO's document, spreadsheet, presentation, PDF, Project, Access, EPUB, invoicing, and conversion engines.

Stars 654
Forks 82
Open issues 1
Total downloads 4,320,051
Release OfficeIMO-v3.5.3
Language: C# Updated: 2026-11-03
Cmdlet

Close-OfficeWord

Module
PSWriteOffice
Inputs
OfficeIMO.Word.WordDocument

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

Syntax

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

Description

Provides a cmdlet wrapper for WordDocument.Dispose/Save so scripts need not call .NET methods directly.

Examples

Close without saving.

$doc = Get-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 -Open

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

Parameters

-Current SwitchParameter optionalsets: Current
Close the most recently tracked document.
-Open SwitchParameter optionalaliases: Show
Open the file after saving. Requires -Save or -Path.
-Password String 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.
-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.