Forum Discussion
Hi Alex,
My Objective is to open an excel workbook and retrive data from different worksheets. Also I need to access worksheets by their name.
If I use "new ActiveXObject" in my Function, I get error "JavaScript runtime error. ReferenceError: ActiveXObject is not defined "on the first line itself.
and If I get "getActiveXObject" the I get "JavaScript runtime error. TypeError: aobjWorkbook.Sheets is not a function" on 4th line.
In below mentioned function, ExcelPath is the path of Excel file That I am trying to open and sheetName is name of the the worksheet.
function get_valid_row_count (ExcelPath,sheetName)
{
var objExcel = new ActiveXObject("Excel.Application"); // ---------first line
//objExcel.Visible = true;
var aobjWorkbook = objExcel.Workbooks.Open(ExcelPath);
var sheet = aobjWorkbook.Sheets(sheetName) // -------4th line
var iUsedRowCount =sheet.ActiveSheet.UsedRange.Rows.Count;
var ValidRowCnt = (iUsedRowCount-1);
return ValidRowCnt;
}
Regards,
Meenakshi
Hi Meenakshi,
If I use "new ActiveXObject" in my Function, I get error "JavaScript runtime error. ReferenceError: ActiveXObject is not defined "on the first line itself.
Ah, indeed, my bad - this is clearly described in the https://support.smartbear.com/testcomplete/docs/scripting/specifics/javascript-for-jscript-users.html help topic: "new ActiveXObject() is not supported in JavaScript. Use Sys.OleObject or getActiveXObject instead."
Try to use Sys.OleObject and check if it helps.
Also read the referenced article and check if it contains something that matters to you. (I am not JavaScript guy and well may miss some important detail.)
P.S. Also, https://smartbear-cc.force.com/portal/KbArticleViewer?name=Get-COM-reference-for-a-running-Excel-instance&sp=testcomplete is something that you must be aware of as you are working with Excel via COM.
Related Content
- 5 years agounderqualified
- 5 years agobatilmoore
- 3 years agogoogleid_114550
Recent Discussions
- 3 days agovladd1