For those not familiar with what Intellisense is:
Intellisense is the feature that detects what you are typing and suggests AutoCompletion, as well as lists the number and type of arguments and whether they are optional and have a default value.
I think the example most of us are probably familiar with is the msgbox. If you for example start to type msgbox in your code, or in the immediate pane you will see the following:
The example shows that you are currently working on the Promt parameter of the msgbox function. If you are familier with reading the display, you will see that Promt is not optional but the remaining parameters are (Since they are enclosed in square brackets []. You will also see that the next parameter is of type vbMsgBoxStyle and it has a default value vbOkOnly.
If you type a "," you will proceed to working/writing the next paramater Buttons. Neatly enough the VBA editor will show a dropdown of the acceptable values, as shown below:
If you start typing the editor will highlight the first acceptable option that matches what you have allready typed.
Creating your own intellisense:
Now if you write a simple function you will still see most of the information that you see in the first of the above msgbox examples. But if you also want to provide the coder (or yourself) with the list of acceptable values, you can even do that too.
First we need to create an Enumeration which we do in a seperate module:
Expand|Select|Wrap|Line Numbers
- Public Enum cmDisplayImage
- cmNoImage = 0
- cmCritical = 16
- cmExclamation = 48
- cmInformation = 64
- End Enum
Then when I write my function, I specify the parameter type to be of cmDisplayImage as shown below:
Expand|Select|Wrap|Line Numbers
- Public Function CustomMessageBox(strCaption As String, Optional cmImage As cmDisplayImage = cmNoImage) As Integer
When I use it, it looks like this:
If you have any questions please don't hesitate to ask. If you have question about the actual text of this article please post/reply here. If you have questions about implementing it yourself, I suggest you start a new seperate Question and link to this article.