如何从vba调用xll addin函数? [英] How do I call an xll addin function from vba?

查看:238
本文介绍了如何从vba调用xll addin函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个第三方XLL插件我想包装在我自己的自定义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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆