Currently I am following this procedure:
- Create some C# class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace TestAgain
{
public class Test
{
void testIt() {
MessageBox.Show("Yellow world");
}
}
}
- Sign the project.
- In AssemblyInfo.cs set
[assembly: ComVisible(false)]
to[assembly: ComVisible(true)]
. - Build the project.
- Run regasm
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe" -tlb -codebase "C:\Users\sancarn\Desktop\tbd\TestAgain\TestAgain\bin\Debug\TestAgain.dll" -verbose
The output from regasm is as follows:
Microsoft .NET Framework Assembly Registration Utility version 4.7.3056.0
for Microsoft .NET Framework version 4.7.3056.0
Copyright (C) Microsoft Corporation. All rights reserved.
Types registered successfully
Type 'TestAgain.Test' exported.
Assembly exported to 'C:\Users\sancarn\Desktop\tbd\TestAgain\TestAgain\bin\Debug\TestAgain.tlb', and the type library was registered successfully
So the type TestAgain.Test
is exported and the type library has been registered. Great!
So I go to Excel-VBA and test it with:
Sub testIt()
Dim o As Object
Set o = CreateObject("TestAgain.Test")
Call o.testIt
End Sub
And get the error Error 429: ActiveX component can't create object
. I.E. It's not registered?
Has anyone got any ideas as to why this isn't working?
Note: I have managed to get a Com-Visible application before with interfaces but I've been looking for a cleaner method and a user told me regasm could do the job.