How to call .NET methods from Excel VBA?
<p>I found a way to call .NET 2 code directly from VBA code:</p>

<pre class="lang-vb prettyprint-override"><code>Dim clr As mscoree.CorRuntimeHost
Set clr = New mscoree.CorRuntimeHost
clr.Start
Dim domain As mscorlib.AppDomain
clr.GetDefaultDomain domain
Dim myInstanceOfDotNetClass As Object
Set myInstanceOfDotNetClass = domain.CreateInstanceFrom("SomeDotNetAssembly.dll", "Namespace.Typename").Unwrap
Call myInstanceOfDotNetClass.ExecuteSomeDotNetMethod
</code></pre>

<p>I added references to mscoree.tlb and mscorlib.tlb to Excel VBA using Tools -> References.</p>

<p>This works for .NET CLR 2 assemblies, up to .NET framework version 3.5.</p>

<p>I need to make it work with .NET 4.</p>

<p>I understood that .NET CLR4 introduced another, version agnostic, way of creating an instance of the runtime and I have found a code example written in C++:
<a href="http://dev.widemeadows.de/2014/02/04/hosting-the-net-4-runtime-in-a-native-process/" rel="noreferrer">http://dev.widemeadows.de/2014/02/04/hosting-the-net-4-runtime-in-a-native-process/</a></p>

<p>My Excel VBA skills are not enough to translate those few lines of code.</p>