Skip to main content

Rename-Worksheet

Command Description

Rename Worksheet

Command Prototype

Excel.SheetRename(objExcelWorkBook,sheet,strNewName,bSave)

Parameter Description

ParameterRequiredTypeDefaultDescription
objExcelWorkBookTrueexpressionobjExcelWorkBookExcel workbook object (workbook opened with "Open Excel" command (Excel.OpenExcel) or the workbook object returned by the command "Bind Excel" (Excel.BindBook))
sheetTruestring"Sheet1"In the worksheet to be renamed., the string means sheet name. The number means sheet order(starting from 0)
strNewNameTruestring"newName"Name of the new created worksheet
bSaveTruebooleanNoneSave immediately after the operation

Demo

/************************Rename worksheet************************ ********* 
**Input 1:
** objExcelWorkBook--Excel workbook object (a workbook opened using the "Open Excel" command (Excel.OpenExcel) or a job bound using the "Bind Excel" command (Excel.BindBook) book object).
**Entry 2:
** sheet--The worksheet to be renamed, if a string is used, it means the name of the specified worksheet; if a number is used, it means the order of the specified worksheet (starting from 0).
**Entry 3:
** strNewName--The name of the new worksheet created.
**Entry 4:
** bSave--The operation is completed and saved immediately. (boolean true/false)
**
*********************************************************************/

objExcelWorkBook = Excel.OpenExcel(@res"Test.xlsx",True,"Excel","","")
Excel.SheetRename(objExcelWorkBook,"Sheet2","newName",False)
TracePrint "Rename sheet: Excel object 'Sheet2' sheet has been renamed to 'newSheet'"
Excel.CloseExcel(objExcelWorkBook,True)