Classic VBA and .NET

Posted on 2004-11-02
Last Modified: 2010-04-15
I have a C# form that I would like to display whenever Word is opened.  Right now, I think I'm going to make a C# class, exposed as a COM object like this:

class Activator {
   MyForm f;
   public void Init(Document document) {
      f = new MyForm(document);
   public void Destroy() {

2 questions:
1) How do I expose the Activator class as a COM object that I can access from VBA?  Most importantly, what registration would I have to do on the user's computer to be able to use this class?
2) If I use the following VBA code:
Set a = CreateObject("Activator")
a.Init ThisDocument
Will my form remain on the screen until I call a.Close or will the Activator object go out of scope?
Question by:thedude112286
    LVL 3

    Accepted Solution

    about question 1

    you have 2 ways to expose :
    a- use GUID

    public class ConfigurationBuilder : IConfigurationBuilder


    b- use the ClassInterfaceType


    public class ConfigurationBuilder : IConfigurationBuilder


    VBA client would use this object as ordinary COM
    'declare events and NetForm object
    Dim WithEvents NetEvent As NetForm
    Dim dotNetForm As New NETobject.NetForm

    Set NetEvent = dotNetForm


    2- will get out of scope
    LVL 3

    Expert Comment

    LVL 4

    Author Comment

    How would I keep my COM class from going out of scope and closing my form?
    LVL 3

    Expert Comment

    thanx very much

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applicationsā€¦
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video discusses moving either the default database or any database to a new volume.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now