c# - VBA 中自定义 COM 类中的 IntelliSense

标签 c# vba visual-studio com intellisense

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

例如在下面的示例中,每当我按下点(或快捷键 ctrl+space)时,我都希望显示“数字”: enter image description here

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

enter image description here

那么,有什么建议呢?

建议1:

enter image description here

最佳答案

简单的例子可能是这样的。

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

enter image description here

enter image description here

enter image description here

关于c# - VBA 中自定义 COM 类中的 IntelliSense,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41162601/

相关文章:

c# - HttpWebRequest:无法连接到远程服务器

vba - Excel VBA : MoviesByGenre Function

amazon-web-services - 无法在 Amazon (aws) 上创建/删除/发布 Lambda,收到 403 拒绝访问

javascript - 如何获得在 Visual Studio 2015 中运行的 Cordova 项目模板?

c# - 如何计算 UWP BackgroundDownloader 中的下载速度?

c# - Team Foundation Server 的 "Client"和 "WebApi"库有什么区别?

excel - VBA for Excel : Server Data Not Updating

excel - 在一组 16 中迭代 4 组的组合

c# - 使用智能在 c# 中取缔字符串

c# - 如何在 Windows Phone 8.1 上实现证书锁定