89

In Excel 2007, how do I add a description and parameter hints to a user-defined function? When I start typing a function invocation for a built-in function, Excel shows a description and parameter list--a tooltip. I'd like to do the same for the functions I define.

Not just for the formula insert wizard, but in the formula box, so if I key "=myFun(", at the "(" the tooltip pops up just like it does for "=average("

There's no help in VBA Help, none on MSDN and none on any of the Excel and VBA dedicated forums I can find, so this is clearly a long shot.

4
  • Not a tooltip ... but is something ... xcell05.free.fr/english/index.html HTH! Commented Nov 24, 2010 at 0:39
  • Thanks b. It looks a little scary, but if it works, it's a solution. Commented Dec 1, 2010 at 21:16
  • This is now supported for VBA and other types of add-ins (.NET, Python etc) with the Excel-DNA IntelliSense extension: excel-dna.net/2016/11/24/…
    – Govert
    Commented Nov 28, 2016 at 13:03
  • I usually provide instructions to my users to type =myfunction("help") to get the syntax help and just put an if statement to return the intellisense. curious to see if Govert's approach works too. Commented Apr 4, 2017 at 16:45

9 Answers 9

122

Not a tooltip solution but an adequate workaround:

Start typing the UDF =MyUDF( then press CTRL + Shift + A and your function parameters will be displayed. So long as those parameters have meaningful names you at-least have a viable prompt

For example, this:

=MyUDF( + CTRL + Shift + A

Turns into this:

=MyUDF(sPath, sFileName)

2
  • 4
    Despite people doubt it helps OP this is the most upvoted input in the thread (my vote included). Which proves that SO is not about helping particular OP but about helping community in general. Thank you.
    – hypers
    Commented Oct 23, 2017 at 16:03
  • Built-in functionality <3 -- This greatly helps when your company applies strict policies about software extensions downloads/installation. Also, this forces the developer to provide useful arguments names -> +1
    – Joël
    Commented Apr 9, 2021 at 9:46
71

Professional Excel Development by Stephen Bullen describes how to register UDFs, which allows a description to appear in the Function Arguments dialog:

Function IFERROR(ByRef ToEvaluate As Variant, ByRef Default As Variant) As Variant
    If IsError(ToEvaluate) Then
        IFERROR = Default
    Else
        IFERROR = ToEvaluate
    End If
End Function

Sub RegisterUDF()
    Dim s As String
    s = "Provides a shortcut replacement for the common worksheet construct" & vbLf _
    & "IF(ISERROR(<expression>), <default>, <expression>)"

    Application.MacroOptions macro:="IFERROR", Description:=s, Category:=9
End Sub

Sub UnregisterUDF()
    Application.MacroOptions Macro:="IFERROR", Description:=Empty, Category:=Empty
End Sub

From: http://www.ozgrid.com/forum/showthread.php?t=78123&page=1

To show the Function Arguments dialog, type the function name and press CtrlA. Alternatively, click the "fx" symbol in the formula bar:

enter image description here

4
  • New arguments in the method allow for the description of function parameters.
    – Wilhelm
    Commented Nov 7, 2011 at 21:04
  • I still don't get it, can you make it more simple please? Is IFERROR the original function where you show the description or is it a helper function which is needed to register the UDF?!
    – Black
    Commented Nov 10, 2016 at 9:32
  • 1
    Couple of years later, IFERROR is the original function. (un)RegisterUFD are the helpers that (un)apply to it the help text.
    – Felício
    Commented May 24, 2018 at 18:04
  • 1
    Still works in 2022! There are multiple "Category:=14" from microsoft to force the type registration for then function:: Integer Category 1 Financial 2 Date & Time 3 Math & Trig 4 Statistical 5 Lookup & Reference 6 Database 7 Text 8 Logical 9 Information 10 Commands 11 Customizing 12 Macro Control 13 DDE/External 14 User Defined 15 First custom category ... 32 Eighteenth custom category learn.microsoft.com/en-us/office/vba/api/…
    – Apsis0215
    Commented Sep 30, 2022 at 22:51
18

I know you've accepted an answer for this, but there's now a solution that lets you get an intellisense style completion box pop up like for the other excel functions, via an Excel-DNA add in, or by registering an intellisense server inside your own add in. See here.

Now, i prefer the C# way of doing it - it's much simpler, as inside Excel-DNA, any class that implements IExcelAddin is picked up by the addin framework and has AutoOpen() and AutoClose() run when you open/close the add in. So you just need this:

namespace MyNameSpace {
    public class Intellisense : IExcelAddIn {
        public void AutoClose() {
        }
        public void AutoOpen() {
            IntelliSenseServer.Register();
        }
    }
}

and then (and this is just taken from the github page), you just need to use the ExcelDNA annotations on your functions:

[ExcelFunction(Description = "A useful test function that adds two numbers, and returns the sum.")]
public static double AddThem(
    [ExcelArgument(Name = "Augend", Description = "is the first number, to which will be added")] 
    double v1,
    [ExcelArgument(Name = "Addend", Description = "is the second number that will be added")]     
    double v2)
{
    return v1 + v2;
}

which are annotated using the ExcelDNA annotations, the intellisense server will pick up the argument names and descriptions.

enter image description here enter image description here

There are examples for using it with just VBA too, but i'm not too into my VBA, so i don't use those parts.

1
9

Also you can use, this Macro to assign Descriptions to arguments and the UDF:

Private Sub RegisterMyFunction()
Application.MacroOptions _
    Macro:="SampleFunction", _      '' Your UDF name
    Description:="calculates a result based on provided inputs", _
    Category:="My UDF Category", _  '' Or use numbers, a list in the link below
    ArgumentDescriptions:=Array( _  '' One by each argument
        "is the first argument.  tell the user what it does", _
        "is the second argument.  tell the user what it does")
End Sub

Credits to Kendall and the original post here. For the UDF Categories

1
  • I've placed it in Workbook_Open() and it needs to be Public. Works here in Excel 2013. Excellent! Commented Jan 8, 2020 at 4:05
7

I just create a "help" version of the function. Shows up right below the function in autocomplete - the user can select it instead in an adjacent cell for instructions.

Public Function Foo(param1 as range, param2 as string) As String

    Foo = "Hello world"

End Function

Public Function Foo_Help() as String

Foo_Help = "The Foo function was designed to return the Foo value for a specified range a cells given a specified constant." & CHR(10) & "Parameters:" & CHR(10)
& "  param1 as Range   :   Specifies the range of cells the Foo function should operate on." & CHR(10)
&"  param2 as String  :   Specifies the constant the function should use to calculate Foo"
&" contact the Foo master at [email protected] for more information."

END FUNCTION

The carriage returns improve readability with wordwrap on. 2 birds with one stone, now the function has some documentation.

2
  • 2
    I like this method because it avoids all the crazy things you have to do if you want real Excel-like tooltips for your UDFs. Commented Nov 11, 2015 at 16:25
  • This seems like a great idea. If the user is paying attention, they will see the alternate UDF with the _Help suffix. I tried it myself. Not having a good time with it, though. It goes through recalc cycles, sometimes until I get a circular reference warning. Not sure what that's about. No precedents, just returning a null string to the cell. Before someone asks, I don't have application.volatile (either true or false) in my UDF.
    – riderBill
    Commented Dec 8, 2015 at 10:57
6

@will's method is the best. Just add few lines about the details for the people didn't use ExcelDNA before like me.

Download Excel-DNA IntelliSense from https://github.com/Excel-DNA/IntelliSense/releases

There are two version, one is for 64, check your Excel version. For my case, I'm using 64 version.

Open Excel/Developer/Add-Ins/Browse and select ExcelDna.IntelliSense64.xll.

Insert a new sheet, change name to "IntelliSense", add function description, as https://github.com/Excel-DNA/IntelliSense/wiki/Getting-Started

Then enjoy! :)

enter image description here

2

Unfortunately there is no way to add Tooltips for UDF Arguments.
To extend Remou's reply you can find a fuller but more complex approach to descriptions for the Function Wizard at
http://www.jkp-ads.com/Articles/RegisterUDF00.asp

2
  • Since Office 2010 arguments can be annotated via this answer.
    – Wilhelm
    Commented Nov 7, 2011 at 21:06
  • @Wilhelm, thats correct but still does not provide tooltips even in XL 2010 Commented Nov 8, 2011 at 9:05
1

I tried @ScottK's approach, first as a side feature of my functional UDF, then as a standalone _Help suffix version when I ran into trouble (see below). In hindsight, the latter approach is better anyway--more obvious to a user attentive enough to see a tool tip, and it doesn't clutter up the functional code.

I figured if an inattentive user just typed the function name and closed the parentheses while he thought it over, help would appear and he would be on his way. But dumping a bunch of text into a single cell that I cannot format didn't seem like a good idea. Instead, When the function is entered in a cell with no arguments i.e.

   = interpolateLinear() 
or
   = interpolateLinear_Help()

a msgBox opens with the help text. A msgBox is limited to ~1000 characters, maybe it's 1024. But that's enough (barely 8^/) for my overly tricked out interpolation function. If it's not, you can always open a user form and go to town.

The first time the message box opened, it looked like success. But there are a couple of problems. First of course, the user has to know to enter the function with no arguments (+1 for the _Help suffix UDF).

The big problem is, the msgBox reopens several times in succession, spontaneously while working in unrelated parts of the workbook. Needless to say, it's very annoying. Sometimes it goes on until I get a circular reference warning. Go figure. If a UDF could change the cell formula, I would have done that to shut it up.

I don't know why Excel feels the need recalculate the formula over and over; neither the _Help standalone, nor the full up version (in help mode) has precedents or dependents. There's not an application.volatile statement anywhere. Of course the function returns a value to the calling cell. Maybe that triggers the recalc? But that's what UDFs do. I don't think you can not return a value.

Since you can't modify a worksheet formula from a UDF, I tried to return a specific string --a value --to the calling cell (the only one you can change the value of from a UDF), figuring I would inspect the cell value using application.caller on the next cycle, spot my string, and know not to re-display the help message. Seemed like a good idea at the time--didn't work. Maybe I did something stupid in my sleep-deprived state. I still like the idea. I'll update this when (if) I fix the problem. My quick fix was to add a line on the help box: "Seek help only in an emergency. Delete the offending formula to end the misery.

In the meantime, I tried the Application.MacroOptions approach. Pretty easy, and it looks professional. Just one problem to work out. I'll post a separate answer on that approach later.

1

A lot of dancing around the answer. You can add the UDF context help, but you have to export the Module and edit the contents in a text editor, then re-import it to VBA. Here's the example from Chip Pearson: Adding Code Attributes

Not the answer you're looking for? Browse other questions tagged or ask your own question.