Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to call a user defined function with eval in Oulook VBA ?

Status
Not open for further replies.

pfav

Programmer
Aug 21, 2020
1
FR
I am trying to call a user defined function in Outlook VBA with eval, but script control seems not to recognize my local functions :

Code:
Public Function myFunc() As String
myFunc = "foo"
End Function
...
Dim sc As Object
Set sc = CreateObject("MSScriptControl.ScriptControl")
sc.Language = "vbscript"
MsgBox sc.Eval("myFunc()")
throws error: "Incompatible type: myFunc"

Any help ?
 
Why not directly from VBA:
[tt]MsgBox myFunc()[/tt]

combo
 
>script control seems not to recognize my local functions

Well no - you need to add the functions to the script ... investigate AddCode. That being said, if these are local functions in VBA, then I echo combo's question

>error: "Incompatible type: myFunc"

I presume this is a translation, as I'd expect the error in English to be "Type Mismatch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top