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()

Community
  • 1
  • 1
Albert D. Kallal
  • 42,205
  • 3
  • 34
  • 51
  • Isn't the class name `CorRuntimeHost`? Does `CreateObject("mscoree.CorRunTimeHost")` give you a `Host` set to `Nothing`? – Mathieu Guindon May 03 '15 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`. – Comintern May 03 '15 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! – Albert D. Kallal May 04 '15 at 03:51

1 Answers1

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".

Comintern
  • 21,855
  • 5
  • 33
  • 80
  • 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. – Albert D. Kallal May 04 '15 at 03:50