vba 在excel中通过VBA调用COM加载项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12373080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 17:41:11  来源:igfitidea点击:

Call COM add-in via VBA in excel

excelvbaautomationvsto

提问by user1662706

I have a COM add-in written in VSTO that I want to call using a VBA macro. With the add-in I need to launch it, enter some text (automatically), then run the application. The add-in is all push button, and I can't readily access the code as some of it is encrypted (it is 3rd party). Regrettably the record function doesn't pick up any activity when clicking this add-in, and I've been unable to add it to the references list on the VBA. I've tried several ways of doing this and none have worked so far.

我有一个用 VSTO 编写的 COM 加载项,我想使用 VBA 宏调用它。使用加载项,我需要启动它,输入一些文本(自动),然后运行应用程序。加载项都是按钮,我无法轻松访问代码,因为其中一些是加密的(它是第 3 方的)。遗憾的是,当单击此加载项时,记录功能没有获取任何活动,而且我无法将其添加到 VBA 上的引用列表中。我已经尝试了几种方法来做到这一点,但到目前为止都没有奏效。

Thank you for your help!

感谢您的帮助!

-Nick

-缺口

As is this is my code. As written, it throws a Run Time Error 91 code on the second to last line of code. If I add parentheses around the last line list I get a syntax error (Expected:=). I'm not sure what the issue is?

这是我的代码。正如所写,它会在倒数第二行代码中抛出运行时错误 91 代码。如果我在最后一行列表周围添加括号,则会出现语法错误(预期:=)。我不确定是什么问题?

Sub Test()
    Dim addIn As COMAddIn
    Dim automationObject As Object
    Dim SQL_CODE As String
    Dim PW As String
    Dim Name As String
    Set addIn = Application.COMAddIns("Orion2010")
    SQL_CODE = "SELECT startdatetime, tli, serialnumber, keyname FROM vmfgoperationdata WHERE serialnumber in ( '90102072B030H' , '90102072003BF') and operationname = 'Part Scanning')"
    PW = "password"
    Name = "na\npiotrowski"
    Set automationObject = addIn.Object
    automationObject.Utility.RefreshData Name, PW, SQL_CODE
End Sub