Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make my objExcel global
#1
Solved: 11 Years, 4 Months, 4 Weeks ago
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?
Reply
#2
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply
#3
Solved: 11 Years, 4 Months, 4 Weeks ago
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?
Reply
#4
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply
#5
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply
#6
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply
#7
Solved: 11 Years, 4 Months, 4 Weeks ago
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?
Reply
#8
Solved: 11 Years, 4 Months, 4 Weeks ago
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading Global Sheet's DataTable Value Bhuvana 0 1,675 01-05-2020, 10:03 PM
Last Post: Bhuvana
  Error as Global Not defined while trying to retrieve value from Datatable siddharth1609 0 986 09-11-2019, 02:52 PM
Last Post: siddharth1609
  How to make QTP Script to work when system gets locked? ramkumarad 6 12,605 11-02-2017, 03:37 PM
Last Post: Divv
  global object which can be called in any action excellentpawan123 2 2,822 04-01-2015, 07:34 PM
Last Post: babu123
  Local script to make compatible with QC automation2012 1 2,318 01-28-2015, 02:11 PM
Last Post: automation2012

Forum Jump:


Users browsing this thread: 1 Guest(s)