< Back

Select-Worksheet

Wed Jan 15, 2020 1:22 am

NAME Select-Worksheet



SYNOPSIS

Sets the selected tab in an Excel workbook to be the chosen sheet and unselects all the others.





SYNTAX

Select-Worksheet [-ExcelPackage] <ExcelPackage> [-WorksheetName <String>] [<CommonParameters>]



Select-Worksheet -ExcelWorkbook <ExcelWorkbook> [-WorksheetName <String>] [<CommonParameters>]



Select-Worksheet -ExcelWorksheet <ExcelWorksheet> [<CommonParameters>]





DESCRIPTION

Sometimes when a sheet is added we want it to be the active sheet, sometimes we want the active sheet to be left

as it was. Select-Worksheet exists to change which sheet is the selected tab when Excel opens the file.





PARAMETERS

-ExcelPackage <ExcelPackage>

An object representing an ExcelPackage.



Required? true

Position? 1

Default value None

Accept pipeline input? True (ByValue)

Accept wildcard characters? false



-ExcelWorkbook <ExcelWorkbook>

An Excel workbook to which the Worksheet will be added - a package contains one Workbook so you can use

workbook or package as it suits.



Required? true

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-WorksheetName <String>

The name of the worksheet "Sheet1" by default.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-ExcelWorksheet <ExcelWorksheet>

An object representing an Excel worksheet.



Required? true

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES









-------------------------- EXAMPLE 1 --------------------------



PS\\> Select-Worksheet -ExcelWorkbook $ExcelWorkbook -WorksheetName "NewSheet"



$ExcelWorkbook holds a workbook object containing a sheet named "NewSheet"; This sheet will become the [only]

active sheet in the workbook

-------------------------- EXAMPLE 2 --------------------------



PS\\> Select-Worksheet -ExcelPackage $Pkg -WorksheetName "NewSheet2"



$pkg holds an Excel Package, whose workbook contains a sheet named "NewSheet2" This sheet will become the [only]

active sheet in the workbook.

-------------------------- EXAMPLE 3 --------------------------



PS\\> Select-Worksheet -ExcelWorksheet $ws



$ws holds an Excel worksheet which will become the [only] active sheet in its workbook.



RELATED LINKS