有没有一种方法可以在VBA中自己构建的COM类中获取IntelliSense?
例如,在下面的示例中,每当我按下点(或ctrl+space表示快捷方式)时,我都希望显示“数字”:

我想,如果以某种方式解决了这个问题,我也会在这里得到一些关于对象的公共功能的信息:

因此,有甚麽建议呢?
建议1

发布于 2016-12-15 11:35:20
简单的例子可能是这样的。
c#类库名为
IntellisenseDemo代码
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)]表示一个接口作为一个分配接口公开给COM,它只允许后期绑定。
[ClassInterface(ClassInterfaceType.None)]意味着CLR不公开此类型的类接口。COM客户端可以使用IIntellisenseDemo接口中的方法调用该类的成员。
雷公
C:\Windows\Microsoft.NET\Framework\v4.0.30319>regasm C:\Temp\IntellisenseDemo.dll /tlb: C:\Temp\IntellisenseDemo.tlbVBA



https://stackoverflow.com/questions/41162601
复制相似问题