小编Gut*_*tti的帖子

如何从VBA中的另一个特定工作簿调用函数?

我想知道是否有办法从另一个指定的工作簿模块调用VBA函数或方法,因为可以在不使用Application.Run的情况下对特定工作表进行调用.

对于我可以调用的工作表,例如:

ActiveSheet.MyTest() 
Run Code Online (Sandbox Code Playgroud)

如果在工作表模块中定义了MyTest

但我想调用模块中定义的函数

我试过了 :

ActiveWorkbook.MyTestModule()
ActiveWorkbook.VBProject.VBComponents("MyModule").MyTestModule(myArg)
Run Code Online (Sandbox Code Playgroud)

哪些不起作用生成错误对象不支持此方法

我可以打电话

Application.Run(ActiveWorkbook.name & "!MyTestModule", myArg)
Run Code Online (Sandbox Code Playgroud)

但我不确定Application.Run的错误处理,我会发现直接运行该方法更干净

excel vba

17
推荐指数
1
解决办法
6万
查看次数

多态性不适用于C#中泛型类的调用

看起来在以下情况下多态性无法正常工作我有以下定义:

interface BaseInterface{}
interface NewInterface:BaseInterface{}
class NewClass:NewInterface{}

class GenericClass<T> where T:BaseInterface
{
    public string WhoIAm(T anObject)
    {
        return TestPolymorphism.CheckInterface(anObject);
    }
}

class ImplementedClass:GenericClass<NewInterface>{}

class TestPolymorphism
{
    public static string CheckInterface(BaseInterface anInterface)
    {
        return "BaseInterface";
    }

    public static string CheckInterface(NewInterface anInterface)
    {
        return "NewInterface";
    }
}
Run Code Online (Sandbox Code Playgroud)

然后当我打电话:

NewClass nc = new NewClass();
ImplementedClass impClass = new ImplementedClass();
Console.WriteLine("The result is " + impClass.WhoIAm(nc));
Run Code Online (Sandbox Code Playgroud)

我有"结果是BaseInterface"

我希望有"结果是NewInterface"作为nc实现BaseClass和NewClass
什么是获得"NewClass"的最佳方法?

谢谢

c# generics polymorphism interface class

10
推荐指数
1
解决办法
276
查看次数

标签 统计

c# ×1

class ×1

excel ×1

generics ×1

interface ×1

polymorphism ×1

vba ×1