VBA 中的自定义 COM 类 中的 IntelliSense

IntelliSense in custom COM classes in VBA

有没有办法在 VBA 中自己构建的 COM 类 中获取 IntelliSense?

例如在下面的示例中,每当我按下点(或快捷键 ctrl+space 时,我都希望显示 "Number" :

我想,如果以某种方式解决了这个问题,我还会在此处获得有关对象的 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)]表示接口作为调度接口暴露给COM,只启用后期绑定。

[ClassInterface(ClassInterfaceType.None)] 表示 CLR 不公开此类型的 class 接口。 COM 客户端可以使用 IIntellisenseDemo 接口中的方法调用此 class 的成员。

regasm

C:\Windows\Microsoft.NET\Framework\v4.0.30319>regasm C:\Temp\IntellisenseDemo.dll /tlb: C:\Temp\IntellisenseDemo.tlb

VBA