Forum Discussion
Abramova
Staff
14 years agoHi,
What do you mean with "Excel.Application"?
Excel.Application is a run-time object that automates Microsoft Excel via its COM server. See http://msdn.microsoft.com/en-us/library/ms277887.aspx.
You can retrieve a reference to this object with the Sys.OleObject property and use the members of this object to work with Excel files from TestComplete.
Look at:
var ex = Sys.OleObject("Excel.Application");
ex.WorkBooks.Open("c:\a.xls","Sheet1"); //Here the error occurs, error: the Open method of the class WorkBooks failed!
Log.Message(ex.activecell.address)
The error occurs, because you cannot use the WorkBooks.Open method to open a certain sheet.
To get access to the needed sheet, you can use the Worksheets property. For example:
function Test()
{
var ex = Sys.OleObject("Excel.Application");
ex.WorkBooks.Open("c:\a.xls");
ex.Worksheets("Sheet1")
Log.Message(ex.activecell.address)
}