Micro Focus QTP (UFT) Forums
Error while saving an already opened Excel - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Error while saving an already opened Excel (/Thread-Error-while-saving-an-already-opened-Excel)



Error while saving an already opened Excel - TurtleRock - 08-28-2014

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.


RE: Error while saving an already opened Excel - dplank - 08-28-2014

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")