[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Classic VBA and .NET

Posted on 2004-11-02
4
Medium Priority
?
184 Views
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);
      f.Show();
   }
   public void Destroy() {
      f.Close();
   }
}

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?
0
Comment
Question by:thedude112286
  • 3
4 Comments
 
LVL 3

Accepted Solution

by:
zahaby earned 2000 total points
ID: 12478494
about question 1

you have 2 ways to expose :
a- use GUID
[Guid("B6F829AA-D1D0-4f14-9B3E-D8D4FA033819")]

public class ConfigurationBuilder : IConfigurationBuilder

{...}

b- use the ClassInterfaceType

[ClassInterface(ClassInterfaceType.None)]

public class ConfigurationBuilder : IConfigurationBuilder

{...}

USING VBA
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
etc

====================

2- will get out of scope
0
 
LVL 3

Expert Comment

by:zahaby
ID: 12478502
0
 
LVL 4

Author Comment

by:thedude112286
ID: 12506213
How would I keep my COM class from going out of scope and closing my form?
0
 
LVL 3

Expert Comment

by:zahaby
ID: 12576706
thanx very much
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Loops Section Overview
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

834 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