Close-OfficeWord
Closes one or more tracked Word documents, optionally saving them.
Syntax
Close-OfficeWord
[-AllowLoss]
[-Password <SecureString>]
[-Path <String>]
[-Save]
[-Show]
[<CommonParameters>]#CurrentClose-OfficeWord
[-AllowLoss]
[-Document] <WordDocument>
[-Password <SecureString>]
[-Path <String>]
[-Save]
[-Show]
[<CommonParameters>]#DocumentClose-OfficeWord
-All
[-AllowLoss]
[-Password <SecureString>]
[-Save]
[-Show]
[<CommonParameters>]#AllDescription
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 $docDisposes the loaded document instance without saving changes.
Close the most recently tracked document.
Close-OfficeWordCloses 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 -ShowSaves updates to Report-final.docx, opens it, and disposes the document.
Parameters
- -AllowLoss SwitchParameter
- Explicitly accept reported native-save reductions.
- -Password SecureString
- Password used to save the document as an encrypted package.
- -Path String
- Optional target path when saving.
- -Save SwitchParameter
- Persist changes before closing.
- -Show SwitchParameter
- Open the file after saving. Requires -Save or -Path.
- -Document WordDocument
- Word document to close.
- -All SwitchParameter
- 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.