Micro Focus QTP (UFT) Forums

Full Version: Error while saving an already opened Excel
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Team,

I am trying to save an Excel generated by an application to my local drive. When the excel is generated, I do not know the worksheet name, so I tried the following code :

Code:
Set objExcel = Eval("GetObject(,""Excel.application"")")    
objExcel.DisplayAlerts = False
Set xlBook=objExcel.Workbooks
Set xlBook = objExcel.ActiveSheet
xlBook.Activate
xlBook.SaveAs("c:\test.xls")

But QTP throws an error stating : Object required at line number 4 (xlBook.Activate).

I am not able to understand the issue here, as the Excel is open and I can see it.

Any help is appreciated.

Thankx.
Try this:

Code:
Set objExcel = Eval("GetObject(,""Excel.application"")")    
objExcel.DisplayAlerts = False
Set xlBook=objExcel.Workbooks.ActiveWorkbook
Set xlSheet = xlBook.ActiveSheet
xlSheet.Activate
xlBook.SaveAs("c:\test.xls")