API Reference
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
Close without saving.
PS>
$doc = Get-OfficeWord -Path .\Report.docx; Close-OfficeWord -Document $doc
Disposes the loaded document instance without saving changes.
Close the most recently tracked document.
PS>
Close-OfficeWord
Closes the current tracked document when a document handle is not passed explicitly.
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] [-Path <String>] [-Save] [-Show] [<CommonParameters>]
#
CurrentParameters
- Current SwitchParameter
- Close the most recently tracked document.
- Path String
- Optional target path when saving.
- Save SwitchParameter
- Persist changes before closing.
- Show SwitchParameter
- Open the file after saving.
Outputs
System.Object
Close-OfficeWord -Document <WordDocument> [-Path <String>] [-Save] [-Show] [<CommonParameters>]
#
DocumentParameters
- Document WordDocument
- Word document to close.
- Path String
- Optional target path when saving.
- Save SwitchParameter
- Persist changes before closing.
- Show SwitchParameter
- Open the file after saving.
Outputs
System.Object
Close-OfficeWord -All [-Save] [-Show] [<CommonParameters>]
#
AllParameters
- All SwitchParameter
- Close all tracked documents for the current runspace.
- Save SwitchParameter
- Persist changes before closing.
- Show SwitchParameter
- Open the file after saving.
Outputs
System.Object