Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliSense in custom COM classes in VBA

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): enter image description here

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

enter image description here

Thus, what are the suggestions?

Suggestion 1:

enter image description here

like image 425
Vityata Avatar asked Dec 15 '16 11:12

Vityata


People also ask

How do I enable intellisense in VBA?

The Ctrl + Space Keyboard Shortcut In the VB Editor, you can begin to type any word, reference, or variable and then press Ctrl + Space to bring up the Intellisense menu.

What is the shortcut to activate intellisense?

You can easily turn Intellisense on and off And it says, hey Ctrl + Q followed by Ctrl + I will toggle Intellisense on and off. Whenever you see a comma like this in the middle of a shortcut command that is what's known as a chord.

Can you use C# in VBA?

It is possible for VBA code (which is a COM component) to call C# code. VBA can call . NET managed code by using a COM Callable Wrapper (CCW). To allow your C# code to be accessible from VBA you need to make sure that all the necessary types are COM visible.


1 Answers

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

enter image description here

enter image description here

enter image description here

like image 156
Daniel Dušek Avatar answered Oct 02 '22 21:10

Daniel Dušek