未加载外接程序时调用XLA外接程序方法(函数/子) [英] Calling an XLA add-in method (function/sub) when the add-in is not loaded

查看:52
本文介绍了未加载外接程序时调用XLA外接程序方法(函数/子)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过我的VBA代码调用由第三方XL A 加载项提供的方法.

I need to call a method that is provided by a third-party XLA add-in via my VBA code.

已经有使用已加载 XL L 添加的答案-in ,但目的是直接调用该方法.

There are already answers for doing this with a loaded XLL add-in, but the intention is to call the method directly.

推荐答案

基于 e.James的回答进行调用XLL加载项,如果加载项尚未加载,我想出了正确的格式.您可以通过以下方式使用 Application.Run 来调用 .xla 加载项内的方法:

Based on e.James' answer for calling an XLL add-in, I figured out the right format to use if the Add-in isn't already loaded. You can use Application.Run for calling methods inside an .xla Add-in the following way:

如果我们假定.xla文件的路径为 C:\ Program Files \ example.xla ,而我们要调用的方法为 ExampleMethod ,则期望一个整数参数,则调用如下:

If we assume that the path to our .xla file is C:\Program Files\example.xla and the method we want to call is ExampleMethod expecting one integer parameter, then the call would be as follows:

' Method call without return value
Private Sub XLAExample()
    Application.Run "'C:\Program Files\example.xla'!ExampleMethod", 10
End Sub

' Method call with return value (check if you can declare correct type for return value!)
Private Function XLAExample() As Variant
    XLAExample = Application.Run("'C:\Program Files\example.xla'!ExampleMethod", 10)
End Sub

因此您将需要构造一个格式为

So you will need to construct a string of the form

"'<ADDIN_PATH>'!<METHOD_NAME>"

进行调用,然后仅附加所有需要的参数,例如

for the call and then just append all needed parameters like

Application.Run <PATH_AND_METHOD>, <PARAMETER_1>, <PARAMETER_2>, ...


不幸的是,我发现 CuberChase的答案直接像API调用那样声明了该方法,不适用于我的特定.xla文件,也许需要将其加载才能工作.


Unfortunately, I found that CuberChase's answer that declares the method directly like an API call doesn't work with my specific .xla file, maybe it would have needed to be loaded to work.

这篇关于未加载外接程序时调用XLA外接程序方法(函数/子)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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