VBA中自定义COM类中的IntelliSense [英] IntelliSense in custom COM classes in VBA
问题描述
有没有办法在VBA中自己构建的COM类中获取IntelliSense?
Is there a way to get IntelliSense in own built COM classes in VBA?
例如在下面的示例中,每当我按点(或按Ctrl +空格表示快捷方式)时,我都希望显示"Number":
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:
那么,有什么建议?
建议1 :
推荐答案
简单的示例如下所示.
名为#c0代码的c#类库
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)]
表示接口作为Dispinterface公开给COM,仅启用后期绑定.
Note: [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
indicates that an interface is exposed to COM as a dispinterface, which enables late binding only.
[ClassInterface(ClassInterfaceType.None)]
表示CLR不公开此类型的类接口. COM客户端可以使用IIntellisenseDemo
界面中的方法来调用此类的成员.
[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.
高潮
C:\Windows\Microsoft.NET\Framework\v4.0.30319>regasm C:\Temp\IntellisenseDemo.dll /tlb: C:\Temp\IntellisenseDemo.tlb
VBA
VBA
这篇关于VBA中自定义COM类中的IntelliSense的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!