0

I've created a library and can instance this and call methods from Excel VBA no problem, having registered it all for COM interop etc.

[ComVisible(true)]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[Guid("blahblahblah1")]
public interface IThingOne
{
    bool Method1();
}


[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("NameSpace.ThingOne")]
[Guid("blahblahblah2")]
public class ThingONe
{
    public bool Method1() { //Whatever; }
}

If I apply STATIC keyword to the public class ThingOne and the public bool Method1() then how can I call these static methods? I can't instantiate them because they're static. I don't want to instantiate them. I just want to be able to call them.

The most I can get working in VBA is

Dim x as ThingOne

Can't do Dim x as new ThingOne and then I can't get the methods to work e.g. x.Method1

When I do the intellisense dropdown for x I get standard Equals, GetHashCode, GetType and ToString

jamheadart
  • 5,047
  • 4
  • 32
  • 63
  • Since the class is static, call `ThingOne.Method1();` – Jay Buckman Dec 05 '18 at 12:22
  • Why you made your class and method static? Is there any reason to do so? – SᴇM Dec 05 '18 at 12:25
  • Why doesn't it give me intellisense options for this as defined by my interface? Also, it doesn't work - it tells me an object is required, but this might be due to the "whatever" - I'm going to try and simplify the method "whatever" and see what happens. – jamheadart Dec 05 '18 at 12:26
  • @SeM it's a connection class, so I didn't really want to have people create multiple instances of it. I wanted to have it as a static one-off, with the connection initialised each time the "send request" methods are called. – jamheadart Dec 05 '18 at 12:28
  • Strictly speaking I could just make this easy for myself by removing static but I'm curious to why it's not working with intellisense. – jamheadart Dec 05 '18 at 12:28
  • OK after reading the answers in the link provided by @SeM I've decided to remove static altogether. – jamheadart Dec 05 '18 at 12:29
  • @jamheadart you can accept duplicate question and this one will be marked as duplicate and closed. – SᴇM Dec 05 '18 at 12:30

0 Answers0