Deletes one or more worksheets from an Excel Document.



Deletes one or more worksheets from an Excel Document.If the specified worksheet to be added already exists in the workbook,
a random number is appended to the worksheetname to make it unique and then created as a worksheet.
Since delete is a destructive operation, the document is backed up before any work is done on it.
The backup location defaults to the current user&;39;s temp directory
On my system the backup location is as follows:



Instance of an excel document that can be used for editing.

Required? True
Position? 0
Default value  
Accept pipeline input? true (ByValue)
Accept wildcard characters? False


Name of the Worksheet(s) to be deleted.
You can delete more than one worksheet by specifying the names as a comma separated list.

Required? True
Position? 1
Default value  
Accept pipeline input? false
Accept wildcard characters? False

This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (








Example 1

MyfirstDoc is piped to Remove-SLWorkSheet with 3 worksheets to be deleted – A,B,C

Example 2

An instance of MyFirstDoc is stored in a variable named doc which is then passed as a named parameter to Remove-SLWorkSheet.

Example 3

Demonstrates what happens when a user specifies a worksheetname that does not exist in the workbook.

Example 4

List-slworksheet is used to filter out the worksheet names and stored in a variable named &;39;Worksheetnames&;39;.
Remove-sldocument is then called with named parameters

Related links