GetRef does not work if a function is loaded at runtime using LoadFunctionLibrary

I am trying to execute a function from a functional library (which I load at runtime). Everything works if I use Eval or Execute to run the function, but I wanted to use GetRef as indicated in this and this

QTP snippet

 Call LoadFunctionLibrary("/../Libraries/Tests.vbs") Set objCon = CreateObject("ADODB.Connection") objCon.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & "C:\_Work\WorkingFolder\TestList.xlsx" & "';Extended Properties='Excel 12.0;HDR=YES;IMEX=1';" Set objRS = objCon.Execute("Select * from [Sheet1$] Where [To Execute] = 'YES'") Do While Not objRS.EOF 'Eval( objRS.Fields(1).Value) 'Execute objRS.Fields(1).Value Set tcFunc = GetRef(objRS.Fields(1).Value) tcFunc objRS.MoveNext Loop 

In the file /../Libraries/Tests.vbs I have this function

 Sub foo() msgbox "hello" End Sub 

referenced in Excel as shown below

enter image description here

When I try to use GetRefm, QTP throws the following error

Invalid procedure call or argument: 'GetRef' Line (10): "Set tcFunc = GetRef(objRS.Fields(1).Value)".

If foo is defined in a QTP action, then it works, but when I import it from a functional library, it fails. Any idea how to make it work?

EDITING - WORKAROUND SOLUTION

Instead of using LoadFunctionLibrary use ExecuteFile to load the functional library.

+2
source share

Source: https://habr.com/ru/post/945579/


All Articles