Passing a Collection of a Class to a C# VSTO AddIn RRS feed

  • Question

  • I am trying to pass a collection of a simple class to a C# add in. The VBA class collection is simple:

    FirstName as string
    LastName as string
    EmailAddress as string

    The collection is just three (3) items. I've validated that the collection assembles correctly on the VBA side.

    I can pass the collection to the AddIn as an "object", but then I cannot get to the properties of the object on the AddIn side. 

    If I pass a single instance (NOT a collection) of my VBA class (as above) I can use reflection to get the properties and their values on the AddIn side.

    I also tried to accept the parameter on the C# AddIn side as a list, but that didn't work either. For reference, this is the sub that passes the parameters to the AddIn:

    Sub myAPICall(myObject as object, fName as string, apiURL as string, myAPIKey as string)
     Dim addIn as COMAddIn
     dim automationObject as object
     dim x
     Set addIn = Application.COMAddIns("eSignlIveAddIn")
     Set automationObject = addIn.Object
     x = automationObject.ESignLiveAPI_Call(myObject, fNme, apiURL, myAPIKey)
     Set automationObject = Nothing
     Set addIn = Nothing
     MessageBox "Value returned= " & x
    End Sub

    This is the line in the AddIn that accepts the parameters:

    public int myAPICall(object myObj, string fName, string apiURL, string APIKey)
       stuff happens here...

    I can't be the only person that ever needed to pass a VBA collection to a C# VSTO AddIn. Please help.

    Any ideas or advice will be greatly appreciated.


    • Edited by MaxTaylor Wednesday, February 20, 2019 10:19 PM
    Wednesday, February 20, 2019 10:19 PM

All replies

  • [System.Runtime.InteropServices.ComVisibleAttribute(true)]
    public interface IProject
    	void NeedToPass(string k, string o, string s);
    public class Project : IProject
    	public void NeedToPass(string k, string o, string s)


    Sub WhatNeedToPass(ByVal k As String, ByVal o As String, ByVal s As String)
        Dim addIn As COMAddIn
        Dim automationObject As Object
        ComAddinName = "AddInName"
        Set addIn = Application.COMAddIns(ComAddinName)
        Set automationObject = addIn.Object
        automationObject.NeedToPass k, o, s
    End Sub

    This is my example. 

    • Edited by Vytautas A Thursday, February 21, 2019 6:44 AM
    Thursday, February 21, 2019 6:44 AM
  • Thanks for the reply, but I think there is a misunderstanding of my post. And maybe I over-simplified the description. I'm not trying to pass three strings.

    I have no trouble passing string (or other type) parameters to the AddIn. What I cannot figure out is how to pass a VBA "collection" in a manner that allows me to access the properties and values of that collection on the AddIn side.

    Thursday, February 21, 2019 1:45 PM
  • Try check this:

    Friday, February 22, 2019 9:11 AM