Skip to main content

Open-Excel

Command Description

Open an Excel workbook file by specifying the path (the workbook will be created if it does not exist) and return an Excel object. Xls, xlsx and xlsm formats are supported

Command Prototype

objExcelWorkBook = Excel.OpenExcel(sPath,bVisible,appType,pwd,writePwd)

Parameter Description

ParameterRequiredTypeDefaultDescription
sPathTruepath'''C:\Users'''Path to the Excel file. If the file doesn't exist, the command will create a new file in the path
bVisibleTruebooleanTrueWhether to open Excel in visualization mode
appTypeTrueenum"Excel"Open with Excel or WPS Excel
pwdTruestring""Open password of the workbook. Ignore it when creating a new file
writePwdTruestring""Edit password of the workbook. Ignore it when creating a new file

return

objExcelWorkBook,The variable used to save the output of the command.

Demo

/************************Open Excel************************** **************** 
**Input 1:
** sPath--Excel workbook file path, if the specified path does not exist the corresponding file, the command will create the file in this path.
**Entry 2:
** bVisible--whether to open Excel in visual mode. (boolean true/false)
**Entry 3:
** Excel--Open with office software. wps use wps to open
**Entry 4:
** password, file open password
**Entry 5:
** Edit password, the password to edit the file
**Exports:
** objExcelWorkBook--The variable to which the output of the function call is saved.
**
*********************************************************************/

// This command assigns an executable Excel file object to the process, which is a prerequisite/precondition for Excel related commands
objExcelWorkBook = Excel.OpenExcel(@res"Template.xlsx",True,"Excel","","")
TracePrint "Open Excel: Excel file 'test.xlsx' is open in visual mode"
// After the Excel object operation is completed, it is recommended to close the file, otherwise it will occupy the machine memory on a large scale. The command to close the workbook is quoted here as explained below.
Excel.CloseExcel(objExcelWorkBook,False)