API Reference
Cmdlet
Close-OfficeWord
Closes one or more tracked Word documents, optionally saving them.
Remarks
Provides a cmdlet wrapper for WordDocument.Dispose/Save so scripts need not call .NET methods directly.
Examples
Example 1: Close without saving.
PS>
$doc = Get-OfficeWord -Path .\Report.docx; Close-OfficeWord -Document $doc
Disposes the loaded document instance without saving changes.
Example 2: Close the most recently tracked document.
PS>
Close-OfficeWord
Closes the current tracked document when a document handle is not passed explicitly.
Example 3: Save to a new path and open the file.
PS>
Close-OfficeWord -Document $doc -Save -Path .\Report-final.docx -Show
Saves updates to Report-final.docx, opens it, and disposes the document.
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.
Syntax
Close-OfficeWord [-Current] [-Password <String>] [-Path <String>] [-Save] [-Show] [<CommonParameters>]#Parameter set:
CurrentParameters
- Current SwitchParameter
- Close the most recently tracked document.
- 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.
- Show SwitchParameter
- Open the file after saving.
Close-OfficeWord -Document <WordDocument> [-Password <String>] [-Path <String>] [-Save] [-Show] [<CommonParameters>]#Parameter set:
DocumentParameters
- Document WordDocument
- Word document to close.
- 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.
- Show SwitchParameter
- Open the file after saving.
Close-OfficeWord -All [-Password <String>] [-Save] [-Show] [<CommonParameters>]#Parameter set:
AllParameters
- All SwitchParameter
- Close all tracked documents for the current runspace.
- Password String
- Password used to save the document as an encrypted package.
- Save SwitchParameter
- Persist changes before closing.
- Show SwitchParameter
- Open the file after saving.