有没有办法在 VBA 中自己构建的 COM 类中获得 IntelliSense?
例如在下面的示例中,每当我按下点(或快捷键 ctrl+space)时,我都希望显示“数字”:
我想,如果这个问题以某种方式得到解决,我也会在这里获得一些关于对象的公共(public)功能的信息:
那么,有什么建议呢?
建议1:
最佳答案
简单的例子可能是这样的。
c# class library named
IntellisenseDemo
code
using System;
using System.Runtime.InteropServices;
namespace IntellisenseDemo
{
[ComVisible(true)]
[Guid("41B3F5BC-A52B-4AED-90A0-F48BC8A391F1")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface IIntellisenseDemo
{
int Number { get; set; }
string TestString(string name);
}
[ComVisible(true)]
[Guid("20EBC3AF-22C6-47CE-B70C-7EBBA12D0A29")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("IntellisenseDemo.Demo")]
public class Demo : IIntellisenseDemo
{
public int Number { get; set; }
public string TestString(string name)
{
throw new NotImplementedException();
}
}
}
注意:[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
表示接口(interface)作为调度接口(interface)公开给 COM,它仅启用后期绑定(bind)。
[ClassInterface(ClassInterfaceType.None)]
表示 CLR 不公开此类型的类接口(interface)。 COM 客户端可以使用 IIntellisenseDemo
接口(interface)中的方法调用此类的成员。
regasm
C:\Windows\Microsoft.NET\Framework\v4.0.30319>regasm C:\Temp\IntellisenseDemo.dll /tlb: C:\Temp\IntellisenseDemo.tlb
VBA
关于c# - VBA 中自定义 COM 类中的 IntelliSense,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41162601/