如何从vba调用xll addin函数? [英] How do I call an xll addin function from vba?
问题描述
谢谢
编辑:至少有两种方法可以实现:
选项1: Application.Run(...)
这看起来像最好的方式因为你的参数在被发送到XLL函数之前被自动转换成适当的类型。
public function myVBAFunction (A as Integer,B as String,C as Double)
myVBAFunction = Application.Run(XLLFunction,A,B,C)
End Sub
选项2: Application.ExecuteExcel4Macro(...)
使用此方法,您将必须将任何参数转换为字符串将其传递给XLL函数之前的格式。
公共函数myVBAFunction(A as Integer,B as String,C as Double)
dim macroCall as String
macroCall =XLLFunction(& A
macroCall = macroCall& ,& Chr(34)& B& Chr(34)
macroCall = macroCall& ,& C
macroCall = macroCall& )
myVBAFunction = Application.ExecuteExcel4Macro(macroCall)
End Sub
有关详细信息,请参见此页面。
I have a 3rd party XLL addin I'd like to wrap in my own custom vba function. How would I call the 3rd party function from my code?
Thanks
Edit: There are at least two ways to do this:
Option 1: Application.Run(...)
This looks like the best way to go about it, since your arguments are automatically converted to an appropriate type before being sent to the XLL function.
Public Function myVBAFunction(A as Integer, B as String, C as Double)
myVBAFunction = Application.Run("XLLFunction", A, B, C)
End Sub
See this page for more details.
Option 2: Application.ExecuteExcel4Macro(...)
With this method, you will have to convert any arguments into string format before passing them to the XLL function.
Public Function myVBAFunction(A as Integer, B as String, C as Double)
dim macroCall as String
macroCall = "XLLFunction(" & A
macroCall = macroCall & "," & Chr(34) & B & Chr(34)
macroCall = macroCall & "," & C
macroCall = macroCall & ")"
myVBAFunction = Application.ExecuteExcel4Macro(macroCall)
End Sub
See this page for more details.
这篇关于如何从vba调用xll addin函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!