Micro Focus QTP (UFT) Forums
How to use the same Excel sheet for 2 different Actions? - 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: How to use the same Excel sheet for 2 different Actions? (/Thread-How-to-use-the-same-Excel-sheet-for-2-different-Actions)



How to use the same Excel sheet for 2 different Actions? - Uma - 09-29-2011

Hi,
I am using one Excel sheet(It has 9 pages,1st page for action 1 and all the other 8 pages for Action 2).
Both the Actions are Reusable.
If I run my script the First Action opens the Excel sheet and it works fine.
My code for first action
Code:
Set xlWrkbk = xlApp.Workbooks.Open("C:\ListMan.xls")
Set xlWrksht = xlWrkbk.Worksheets("MyDraft") ........
If it comes to the second Action,it gives the following error
Object required: 'xlWrkbk'

Because I didn't use the line
Code:
(Set xlWrkbk = xlApp.Workbooks.Open("C:\ListMan.xls"))
This is my script for second Action.

Code:
Set xlApp = GetObject("","Excel.Application")
If  Not xlApp  Is Nothing Then
Msgbox "ExcelSheet  is already open"
Else
Set xlApp = GetObject("","Excel.Application")
xlApp.visible = true
Set xlWrkbk = xlApp.Workbooks.Open("C:\ListMan.xls")
End If

Set xlWrksht = xlWrkbk.Worksheets("MyLi-Loc")


I used only the following line.
Code:
Set xlWrksht = xlWrkbk.Worksheets("MyDraft") ........

How to use the same Excel sheet for different Actions,without opening and closing againa nd again.
Any help?
Thank you
Uma


RE: How to use the same Excel sheet for 2 different Actions? - rajpes - 09-29-2011

use "Importsheet" method


action2 script:
Code:
Datatable.Importsheet("C:\ListMan.xls","MyDraft1",Action2)
its code here

Datatable.Importsheet("C:\ListMan.xls","MyDraft2",Action2)
its code here
.
.


Datatable.Importsheet("C:\ListMan.xls","MyDraft8",Action2)



RE: How to use the same Excel sheet for 2 different Actions? - Uma - 09-30-2011

Hi Raj,
Thank you for the solution
the code is working,but I did a small modification,
DataTable.ImportSheet "C:\ListMan.xls","Excelsheetname","actionname"
Uma


RE: How to use the same Excel sheet for 2 different Actions? - rajpes - 09-30-2011

that is what i meant dear