IntelliSense in custom COM classes in VBA

旧巷老猫 提交于 2020-01-21 06:37:07

问题


Is there a way to get IntelliSense in own built COM classes in VBA?

E.g. in the example below I would like to get "Number" showing up, whenever I press on the dot (or ctrl+space for shortcut):

I suppose, if this is somehow resolved, I would also get some info concerning the public functions of the objects here:

Thus, what are the suggestions?

Suggestion 1:


回答1:


Simple example could look like this.

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();
        }
    }
}

Note: [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] indicates that an interface is exposed to COM as a dispinterface, which enables late binding only.

[ClassInterface(ClassInterfaceType.None)] means the CLR does not expose a class interface for this type. COM clients can call the members of this class using the methods from the IIntellisenseDemo interface.

regasm

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

VBA



来源:https://stackoverflow.com/questions/41162601/intellisense-in-custom-com-classes-in-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!