2

In the follow post it shows how one can use VBA, create a instance of the CLR and thus call/use/consume .net COM objects without having to register such objects.

Side-By-Side COM Interop with C# and VBA

I looking to replace this code:

Dim Host As mscoree.CorRuntimeHost
Set Host = New CorRuntimeHost

With

Set Host = createObject("mscoree.CorRunTimeHost")

I am unable to find the "class" name.

In other words, I want to late bind the CLR. Does anyone know if it is possible to use VBA CreateObject() in place of the having a hard reference from VBA to the above mscore

The “reference” set in VBA - > tools is

C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscoree.tlb

In effect I looking to late bind use of the .net CLR via CreateObject()

3
  • Isn't the class name CorRuntimeHost? Does CreateObject("mscoree.CorRunTimeHost") give you a Host set to Nothing? Commented May 3, 2015 at 23:48
  • My guess is that it can't be done without adding a COM reference to the typelib in the registry. If I call Debug.Print TypeName(Host), it reports Unknown. Commented May 3, 2015 at 23:50
  • A good crack on this on your part - I believe you are correct - without a typelib in the registry - I cannot late bind. However, it MIGHT be possible if the mscoree.tlb was not managed code! Commented May 4, 2015 at 3:51

1 Answer 1

1

I believe you may need to register the typelib first (can't confirm ATM because I used regtlibv12.exe to register it before I went hunting for the class name). The class name appears to be "CLRMetaData.CorRunTimeHost".

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

1 Comment

Appreciate the class name - unfortunately CreateObject still does not work - I MUCH agree and suspect you are correct - the issue is such a object needs a regasm /codebase to work. Of course avoiding the need to register anything on locked down machines is very much the reason for this post. Funny that a reference set in Access VBA works, but allowing CreateObject does not.

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.