Forum Discussion
7 Replies
- rraghvani
Champion Level 3
DataSheet.xlsx or DataSheet.xlsm? So the Open method is not working? What's the exact error message?
Are you able to open the file normally?
Can you create a blank spreadsheet with a just a few items, and try to open that?
If you do an internet search for "Excel element not found", you will come across many results. The error is specific to Excel, and not TestComplete.
- rraghvani
Champion Level 3
Is it reading the correct file? And is the dialog about giving permissions to run Excel Macros preventing the file from being read?
- csachanandaniOccasional Contributor
Yes, it reads file location, the file has all correct permissions - no changes on that, and then fails at the excelFile = Excel.Open(fileLocation+"Test Data\DataSheet.xlsx") line. Hard time understanding why the tests are failing.
- rraghvani
Champion Level 3
Ensure there's no other instances of Excel running.
Also, I've just noticed, your path is not using double back slash. It should be like,
Excel.Open(fileLocation + "Test Data\\DataSheet.xlsx") // OR Excel.Open(fileLocation + "\\Test Data\\DataSheet.xlsx")
- csachanandaniOccasional Contributor
\\ or \ doesnt matter as it picks correct path. And no excel app is running in background. I am clueless why it is not working. It randomly works and then stops.
- rraghvani
Champion Level 3
Using a single-backslash is used for escaping certain characters. A double-backslash returns a single slash. Also, the example shows
Are you calling the Open method more than once?
I'm curious to know, what is the full path if you were to run,
fileLocation = Project.Path + "Test Data\DataSheet.xlsx" Log.Message(fileLocation) //excelFile = Excel.Open(fileLocation+"Test Data\DataSheet.xlsx") //excelSheet = excelFile.SheetByTitle["Test Data"]
- csachanandaniOccasional Contributor
excelFile = Excel.Open("C:\\Automation\\Test Data\\DataSheet.xlsm") didnt work either. Also, Open method is called only once and then we read data from different sheets.