I’m creating classs library by using C# that will be used from VBA. But one thing discurages me – when I delete or change some letters in a method name and try to compile vba project then I get no errors. But I want to get compile error message if As I found out it happens because of using late binding.
I’ll try to explain.
-
It is correct signature:
Sub Test() Dim cls as New SomeClass cls.SomeMethod End Sub -
It is signature with misspelling:
Sub Test() Dim cls as New SomeClass cls.**SomeMetod** End Sub -
Press Compile VBA Project – everything is ok, but it shouldn’t be.
I’ve changed base interface as shown below:
[Guid("Some GUID here"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IComInterface
{}
and base class:
[ClassInterface(ClassInterfaceType.None)]
public class BaseClass
But nothing happens!!! I only get errors at runtime.
Solution is:
and base class:
Be aware that versioning of your code will be not supported! Also .NET methods like ToString(), GetHashCode() etc became visible in VBA. So you will need to use attribute [ComVisible(false)] for these methods. This will work for ToString, GetHashCode, Equals. GetType impossible to hide in that case. So you need to decide wether you need to hide .NET methods or have early binding and complation warnings