Add-in with C#

To create a VBE add-in for the Visual Basic Editor you can use C#.
Create a [[COM Add-in]] that implements the IDTExtensibility2 interface.


Creating

Open Visual Studio 2022 as Administrator.
New Project, Visual C#, Windows Desktop, Class Library (.NET Framework).
Change the Name to "VBECOMAddin".
Change the Location to somewhere on your C drive.
Check the .NET Framework version is correct and press OK.
Rename the Class1.cs file to MyConnect.cs.
Add four references to this project, (Project > Add Reference).
(1) Assemblies, Framework: "System.Windows.Forms"
(2) COM, Type Libraries: "Microsoft Office 16.0 Object Library".
(3) COM: Type Libraries: "Microsoft Visual Basic for Applications Extensibility 5.3" (VBIDE)
(4) COM: Type Libraries: "Microsoft Add-in Designer" (Extensibility)
Remove the default class.
Add the following class underneath the interface in the MyConnect.cs file.

namespace VBECOMAddin 
{
    [System.Runtime.InteropServices.ProgId("VBECOMAddin.MyConnect")]
    [System.Runtime.InteropServices.Guid("0B58C36E-DE4E-4C40-8ED2-960437BFB7B1")]
    [System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
    [System.Runtime.InteropServices.ComVisible(true)]
    [System.Runtime.InteropServices.ComDefaultInterface(typeof(Extensibility.IDTExtensibility2))]
    public class MyConnect : Extensibility.IDTExtensibility2
    {
        public void OnConnection(
            object Application,
            Extensibility.ext_ConnectMode ConnectMode,
            object AddInInst,
            ref System.Array custom)
        {
            System.Windows.Forms.MessageBox.Show("onConnection");
        }
        public void OnDisconnection(
            Extensibility.ext_DisconnectMode RemoveMode,
            ref System.Array custom)
        { }
        public void OnAddInsUpdate(ref System.Array custom)
        { }
        public void OnStartupComplete(ref System.Array custom)
        { }
        public void OnBeginShutdown(ref System.Array custom)
        { }
    }
}

Make sure the Guid Id is replaced using (Tools > Create GUID).
Select Build > Build Solution).
At this point no registry entries are added to the registry.
Project Properties
Build, Platform Target x64
Open "AssemblyInfo.cs"

[assembly: ComVisible(true)] 

When the solution is built the RegAsm tool WILL NOT RUN automatically.
The RegAsm tool adds the necessary class and interface information to the registry.
Tools > Command Line > Developer Command Prompt

"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe" /codebase /tlb VBEAddin.dll 

Registry Keys - COM Add-in

Microsoft Office COM add-ins are identified by reading from the registry.
You can view the registry by going to the Windows start menu, choosing Run, typing regedit and pressing OK.
There must be a key representing the COM Add-in under the Addins key:
64 Bit Office - HKEY_CURRENT_USER\Software\Microsoft\VBA\VBE\6.0\Addins64\

HKEY_CURRENT_USER\Software\Microsoft\VBA\VBE\6.0\Addins64\VBECOMAddin.MyConnect 
(String)(Default) - (value not set)
(String) Description - VBACOMAddin
(String) FriendlyName - VBACOMAddin
(DWord) LoadBehavior - 3

Description - A brief description of the add-in.
FriendlyName - A user friendly name that is displayed in the COM add-ins dialog box.
Load Behavior - The load behaviour of the add-in.


Visual Basic Editor

(Tools > Addin Manager)


© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext