Skip to main content

VBA versus .NET

Adapter or Wrapper

This is code possible through .NET, in that it bridges across to COM for automation in VBA.  This concept can be extended to work for many other COM-based applications.  This code allows the add-in to expose internal .NET-coded procedures to Excel COM, extending the use of the .NET code.

Salient Characteristic(s)

  • Handle interface between different, incompatible systems
  • The interface is required because COM is interface-based
  • Other code elements are required for this to work properly
    • Registering the DLL
    • Creating the AdapterForVBA class on startup
Code

using System;
using System.Runtime.InteropServices;

namespace DesignPatterns
{
    /// <summary>
    /// Interace to expose VSTO/COM obects for COM and Excel
    /// Used by class below
    /// </summary>
    [ComVisible(true)]
    [Guid("B523844E-1A41-4118-A0F0-FDFA7BCD77C9")]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    public interface IAdapterForVba
    {
        //signatures for methods acessible to VBA go here
        //exists here and in class
    }

    /// <summary>
    /// Class to expose items to VBA and other COM application
    /// </summary>
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.None)]
    public class AdapterForVba : IAdapterForVba
    {
        public AdapterForVba()
        {
            //methods to expose go here
            //exists here and in interface
        }
    }
}

Comments

Popular posts from this blog

Migrating and Design Planning

I have been toying with the idea of migrating one of my sites to a better host - it was supported by Yahoo and now AAbaco - and implementing some newer technologies. Among products I have used at work or are working with peripherally, I am considering using ASP.NET MVC, Entity Framework, ReSTful API's, NoSQL, and Azure-hosted databases - it is currently a mixture of very low-end PHP, HTML5/CSS3, light Javascript, and MySQL - so I decided to write up an architectural diagram - it looks like any standard architecture, with maybe a few additional elements - to help with the planning:

James Igoe's Reviews > Thinking Architecturally

Thinking Architecturally by Nathaniel Schutta My rating: 4 of 5 stars An overview of architectural decisions, the politics and persuasion involved, and the needs to balance competing measures and attributes. A fairly easy read, but full of great suggestions, and, for many, reminders of how to handle being a senior developer or architect. View all my reviews

Do Algorithms Make You a Better Developer?

Responding to a question on HashNode, Developers who practise algorithms are better at software development than people who just do development. Is it true? , I wrote the following: My feeling is that algorithms help make one a better programmer, but that is likely true of many coding concepts. I did not have algorithms as an undergraduate, so my knowledge is acquired through reading and practice, but after reading and applying Algorithm's in a Nutshell, I felt the quality of my work improved. That said, my development work increased more after understanding Design Patterns, or after consuming books on database design.  Since many types of knowledge improve developing and architecting abilities, one has to consider how it helps and to what degree. Algorithms are coding-in-the-small, often narrowly focused solutions, but which can have a great impact at scale. For many applications, a focus on algorithms would be overkill as data sets and requirements do not require it. In this ...