Call COM add-in via VBA in excel

2019-07-17 16:38发布

问题:

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.

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?

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

回答1:

Check these links

How to: Expose Code to VBA in a Visual C# Project

Walkthrough: Calling Code from VBA in a Visual C# Project