Micro Focus QTP (UFT) Forums
Make my objExcel global - 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: Make my objExcel global (/Thread-Make-my-objExcel-global)



Make my objExcel global - mv8167 - 06-23-2011

I create/save/open and work wih an objExcel file in different fuctions. But my usage of it fails. How do I make my objExcel for global usage?


RE: Make my objExcel global - rajpes - 07-05-2011

Either you can define the excel object outside all those functions scope or return the excel object just before the end of function blocks which manipulate on the workbooks


RE: Make my objExcel global - mv8167 - 07-06-2011

To define my Excel objects outside all of my functions, must I then also pass ObjExcel through them all? Currently, I open my Start Up Script which just alls other functions. Here?


RE: Make my objExcel global - rajpes - 07-06-2011

You don't need to pass variables in the global scope (outside functions) as parameters to functions.
You can directly access them in any functions provided they are all in same action script


RE: Make my objExcel global - mv8167 - 07-09-2011

Raj,

Sorry, but I still dont undertstand completely.

Do I need to set obExcel at each function that uses it? If I dont, I get messages indicating that objExcel is not recognized, so I pass objExcel aqnd everything works fine.

I Set my objExcel in my test script. I thought if it was set here, my functions could use it. But, when I use objExcel in other associated functions, the objExcel fails.

What am I doing incorrectly?

thx ;-)

Lor


RE: Make my objExcel global - rajpes - 07-09-2011

Lorena,

If you are using associated functions obviously you will have to pass it.
If you are in same action and it has got its own functions then no need to pass


RE: Make my objExcel global - mv8167 - 07-11-2011

Im only using one action. After I create an Excelave it, must I close and reopen nit using Set objExcel=O:\QTP Tests\QTPOutputData\DocViewHref.xls?


RE: Make my objExcel global - rajpes - 07-11-2011

check if this code template works

Code:
'function library file

function f1(obj)
set wb=obj.workbooks.open("c:\.....\.xls")
set sh=wb.worksheets(1)
'do some operation
set f1=obj

set wb=nothing
set sh=nothing
end function

function f2(obj)
set wb=obj.workbooks.open("c:\.....\.xls")
set sh=wb.worksheets(1)
'do some operation
set f2=obj

set wb=nothing
set sh=nothing
end function

'action script

set e=createobject("excel.application")

set e= f1(e)

set e=f2(e)

set e=nothing