I am using QTP 9.5 and MS Office 2007. My script run successfully, but in the very last line it fails. I am trying to export the results to excel using DataTable.ExportSheet "C:\QTPResults\executionInfo.xls","Global" and it fails!!!
the only message I get is that a general error occured and that is it. I tried to re.build my script and it doesn't work. Any clue?
Thanks a lot for your answers. Yes, I am storing results in the Global Sheet and No, I don't have the file opened while executing the test. It is an existing file though.
It used to work for 2+ years, and all of the sudden it does not work :S
I also tried changing file extension to xlsx, but it saves the file as corrupted :S
This is the error I am getting: Runtime error: A general error occurred while exporting sheet C:\QTPResults\verifyExecutionInfo.xls to file Global
Also, one more interesting thing is that this script has calls to external actions. If I run the code without the call to these external actions, I have no problems. When adding the external actions is when I get the error.
Could it be that your excel sheet has so many sheets ? If the sheet "Global" does not exist in the file, then it would append it to the end. I guess Excel does not support more than 256 sheets. Did you try running this on a totally new file ?
You could try reinstalling. Maybe something got corrupt within QTP. You also said that removing the calls to external actions solves your problem which is sort of wierd. So try reinstalling and all the best !!
Hello. No, it didn't help. As of now, I haven't been able to resolve the problem. It continues to happen some times.
I created some recovery scenarios that get fired every time a general error occurs in QTP. In the recovery scenario, I have the instruction DataTable.ExportSheet "C:\QTPResults\executionInfo.xls","Global"
Same thing as we with the current code. Some times it works, and some others it doesn't :S
Are there other ExportSheet calls before this line? At one point we had an issue like this, and we think it was caused because the first ExportSheet call did not truly finish before the next call started, so the file was actually still in use. That could explain why your recovery scanario sometimes works. If that is the case, you could try adding a Wait statement before your ExportSheet statement to give time for the file to be completely updated.
bcoz of this I am facing another problem; QTP hangs if execution is terminated. If the qtp is in execution mode and user stops the execution. Then next time user is not able to execute. The following error is displayed - "Unable to create the specified run results folder. The folder may be in use by another program. Close other program that are using this folder." The troubleshooting steps taken: 1. Even after disk clean up the problem exists. 2. We tried deleting the temp results folder but we were not able to delete file 'Default.xls'. So every time I had to kill the QTP and its process tree to proceed.
I don't have any exportsheet statements previous to this one, this is the only one in the whole script.
There is something that I've been doing as a workaround, which is obviously not a solution, but it helps saving a 120 rows file, with several lines of comments in each row. This workaround consists on: 1. I add a breakpoint in the line where the excel should be exported. 2. Click F11 to get that line of code executed. 3. I go to the folder where the file should be exported. If it was created, the I resume execution. If it doesn't, then I continue debugging step by step. 4. Right after the export statement, I have the error handling for the script. If it enters the error handling, it means that the export failed. 5. What I do, is to do several actions with the runtime data table until it appeaers like it is frozen and not responding. 6. Then, I have the same export statement within the error handling statements. It gets executed and it works!!!!!
You need to first download the excel attachment from QC to local path. Then work on the sheet using excel objects. I am still working on it.
' Some sample codes on excel objects intRow=1 Set excelObj=CreateObject"Excel.Application") Set workBooks = excelObj.Workbooks.Open("C:\IMPORT\abc.xls") Set workSheets = excelObj.worksheets("abc") For Each c In workSheets.Range("A1:Z1").Cells If c.Value = "XXX" Then intCol = c.Column Exit For End If Next workSheets.Cells(intRow,intCol).value = "Y" workBooks.Save excelObj.Workbooks.Close()