1

Is it possible to reference a COM-registered DLL and then create objects that require arguments in the constructor in VBA code?

I'm successfully referenced the tlb in Access 2013 (64-bit) that was registered with regasm, and I've managed to create a simple object that doesn't need arguments in the constructor.

From what I read, it is not. Do I now face major refactoring?

1
  • Do you specifically need to manipulate the objects in VBA? I ask because the TLBs can be a nightmare when it comes to versions and updates, and I personally avoid them at all costs when developing Office addins. Instead, I create methods in .NET, accessible from VBA calls, and leave all the manipulation of objects inside .NET, with a method to do everything I need. It means I don't need to use regasm but can dynamically call the methods without strongly typing them. Ping me if you want to discuss it further. Commented Sep 28, 2015 at 3:04

1 Answer 1

2

It doesn't have to be "major". You simply need a factory method, one that takes all the arguments you need to construct the object. For example:

public class Foo {
    internal Foo(int arg1, string arg2) {
       // etc...
    }
    // Other methods and properties
    //...
}

public class FooFactory {
    public Foo Create(int arg1, string arg2) {
        return new Foo(arg1, arg2);
    }
}

And now you simply use FooFactory.Create() in your VBA code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.