Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# class library to use with Excel VBA

C# class library to use with Excel VBA

Scheduled Pinned Locked Moved C#
csharpvisual-studiocomquestion
5 Posts 2 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BobbyStrain
    wrote on last edited by
    #1

    I have built a class library using VS 2013 C#. It includes an interface to expose all the functions and public properties. It compiles and registers for use as COM visible. I can readily access the functions in the library from VBA. But there seems to be no way to access public properties in the class library with VBA. All the information I find on the web is for simple applications where there are no public properties, only functions. My efforts suggest that accessing public properties in the library is not doable. Is my conclusion correct? If there is a way to achieve it, maybe someone can point me to a resource.

    P 1 Reply Last reply
    0
    • B BobbyStrain

      I have built a class library using VS 2013 C#. It includes an interface to expose all the functions and public properties. It compiles and registers for use as COM visible. I can readily access the functions in the library from VBA. But there seems to be no way to access public properties in the class library with VBA. All the information I find on the web is for simple applications where there are no public properties, only functions. My efforts suggest that accessing public properties in the library is not doable. Is my conclusion correct? If there is a way to achieve it, maybe someone can point me to a resource.

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      Might not be quite what you're after, but couldn't you expose the properties by means of (explicit) getter and setter functions? Cheers, Peter

      Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

      B 1 Reply Last reply
      0
      • P Peter_in_2780

        Might not be quite what you're after, but couldn't you expose the properties by means of (explicit) getter and setter functions? Cheers, Peter

        Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

        B Offline
        B Offline
        BobbyStrain
        wrote on last edited by
        #3

        Thanks, Peter. I was hoping to avoid having to add/modify the classes that are built for .Net use with methods and properties. But I have not found any other way to approach it other than the one you suggested. On another tack, is there any software to generate an interface from the methods and properties in a class? I use copy/paste/edit which is time consuming. But I do have lots of time. Microsoft has made it difficult to use .Net with VBA, going in either direction. And it's maddening to try to hook to an open Excel workbook from a .Net application. So I gave this up.

        P 1 Reply Last reply
        0
        • B BobbyStrain

          Thanks, Peter. I was hoping to avoid having to add/modify the classes that are built for .Net use with methods and properties. But I have not found any other way to approach it other than the one you suggested. On another tack, is there any software to generate an interface from the methods and properties in a class? I use copy/paste/edit which is time consuming. But I do have lots of time. Microsoft has made it difficult to use .Net with VBA, going in either direction. And it's maddening to try to hook to an open Excel workbook from a .Net application. So I gave this up.

          P Offline
          P Offline
          Peter_in_2780
          wrote on last edited by
          #4

          With regard to "another tack", I don't know of anything, but then I am merely a tourist in the .NET and C# district. Maybe some of the friendly locals might know. Cheers, Peter

          Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

          B 1 Reply Last reply
          0
          • P Peter_in_2780

            With regard to "another tack", I don't know of anything, but then I am merely a tourist in the .NET and C# district. Maybe some of the friendly locals might know. Cheers, Peter

            Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012

            B Offline
            B Offline
            BobbyStrain
            wrote on last edited by
            #5

            I found that Visual Studio has a tool accessible from the context menu to generate the interface. I run into obstacles often when I build a C# library for COM and try to use it in Excel. I have two such libraries with interfaces that appear to be identical in format. One works with Excel, the other does not. However, the one that doesn't work using an interface works OK when I remove the interface. But then nothing is available for VBA intellisense. And the functions don't show in the object explorer with either version. Is there a good book or reference that carefully and fully explains building C# libraries for use with Excel VBA?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups