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