Skip to main content

Copy-Worksheet

Command Description

Create a sheet and copy the specified sheet data into the created one

Command Prototype

Excel.CopySheet(objExcelWorkBook,sheet,strNewSheetName,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"The worksheet to be copied. If a string is used, it refers to the name of the specified sheet. If a number is used, it refers to the index of the specified sheet (starting from 0)
strNewSheetNameTruestring"newSheet"New worksheet name
bSaveTruebooleanNoneSave immediately after the operation

Demo

/************************Copy sheet************************ ********* 
**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 copied worksheet, 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.CopySheet(objExcelWorkBook,"Sheet1","nSheet",False)
TracePrint "Copy Sheet: Excel object 'Sheet1' sheet has been copied and pasted into new sheet 'nSheet'"
Excel.CloseExcel(objExcelWorkBook,True)