GetRef not working if function is loaded at runtime using LoadFunctionLibrary

Deadly 提交于 2019-12-10 22:36:14

问题


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

QTP Code 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 /../Libraries/Tests.vbs file, I have this function

Sub foo()
  msgbox "hello"
End Sub

which is referenced in the Excel as below

When I try to use GetRefm QTP is throwing the below error

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

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

EDIT -- WORKAROUND SOLUTION

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

来源:https://stackoverflow.com/questions/41851543/getref-not-working-if-function-is-loaded-at-runtime-using-loadfunctionlibrary

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!