Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Passing Object from VBA to C#

  • 12-05-2010 04:05PM
    #1
    Registered Users, Registered Users 2 Posts: 1,841 ✭✭✭


    Hi All,

    I've got a VBA / C# 2005 DLL project.

    I want to pass on object from the VBA to the C# DLL. Do I need to do this through an interface?


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Is VBA still based on VB6? If so you can use an interop. If its .NET based you should be okay with native .Net types I think. My memory is not what it used to be. Shouldn't be a big job to convert from VB.NET to C# anyway.


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Yes you can

    You will need to use REGASM to register the assembly that is COM visible so that your VBA application can use it

    Details on REGASM http://msdn.microsoft.com/en-us/library/tzat5yw6%28VS.80%29.aspx

    Examples http://weblogs.asp.net/psteele/archive/2004/06/16/157767.aspx

    Normal convention would be regasm MyAssembly.dll /t:MyAssembly.tlb


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    To pass the VBA object to C# dll that understands it

    myVBAobject = FunctionThatReturnsIt()

    Set NetObject = CreateObject("NETProject.Bar")

    NetObject.AcceptClass(myVBAObect)

    Provided that your .NET class knows what to expect it should be ok...


Advertisement