如何在用户定义的函数上放置工具提示

Mar*_*ult 70 excel vba

在Excel 2007中,如何向用户定义的函数添加描述和参数提示?当我开始为内置函数键入函数调用时,Excel会显示描述和参数列表 - 工具提示.我想对我定义的函数做同样的事情.

不只是公式插入向导,而是在公式框中,所以如果我键"=myFun(",在"("工具提示弹出就像它为"=average("

在VBA帮助中没有任何帮助,在MSDN上没有任何帮助,在我能找到的任何Excel和VBA专用论坛上都没有,所以这显然是一个很长的镜头.

小智 90

不是工具提示解决方案,而是一个充分的解决方法:

开始键入UDF,=MyUDF(然后按CTRL+ Shift+ A,将显示您的函数参数.只要这些参数具有有意义的名称,您至少可以提供可行的提示

例如,这个:

=MyUDF(+ CTRL+ Shift+A

变成这样:

=MyUDF(sPath, sFileName)

  • 尽管人们怀疑它有助于OP这是线程中最受欢迎的输入(包括我的投票).这证明了SO不是为了帮助特定的OP,而是为了帮助整个社区.谢谢. (3认同)

Fio*_*ala 56

Stephen Bullen的专业Excel开发描述了如何注册UDF,它允许描述出现在Function Arguments对话框中:

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
Run Code Online (Sandbox Code Playgroud)

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

要显示"功能参数"对话框,请键入功能名称,然后按CtrlA.或者,单击公式栏中的"fx"符号:

在此输入图像描述


小智 8

我只是创建了一个"帮助"版本的功能.在自动完成功能的正下方显示 - 用户可以在相邻的单元格中选择它以获取指令.

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 master@foo.com for more information."

END FUNCTION
Run Code Online (Sandbox Code Playgroud)

使用wordwrap打开回车符可提高可读性.一石二鸟,现在功能有一些文件.

  • 我喜欢这种方法,因为如果你想为你的UDF提供[真正类似于Excel的工具提示](http://stackoverflow.com/a/17517538/2822719),它可以避免你必须做的所有疯狂的事情. (2认同)

wil*_*ill 8

我知道你已经接受了这个问题的答案,但是现在有一个解决方案,让你可以通过Excel-DNA加入或者在你的内部注册一个智能感知服务器,像其他excel函数一样弹出智能感知样式完成框.自己加入.见这里.

现在,我更喜欢C#的方式 - 它更简单,因为在Excel-DNA中,任何实现的类IExcelAddin都被addin框架拾取AutoOpen()并且AutoClose()在打开/关闭add时运行并运行.所以你只需要这个:

namespace MyNameSpace {
    public class Intellisense : IExcelAddIn {
        public void AutoClose() {
        }
        public void AutoOpen() {
            IntelliSenseServer.Register();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后(这只是从github页面中获取),您只需要在函数上使用ExcelDNA注释:

[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;
}
Run Code Online (Sandbox Code Playgroud)

使用ExcelDNA注释进行注释,智能感知服务器将获取参数名称和描述.

在此输入图像描述 在此输入图像描述

有一些例子也可以和VBA一起使用它,但我不太喜欢我的VBA,所以我不使用那些部分.

  • 这里有一篇关于如何将 Excel-DNA IntelliSense 扩展与 VBA 结合使用的文章:https://fastexcel.wordpress.com/2016/10/07/writing-efficient-vba-udfs-part-15-adding-intellisense -到你的udfs/ (3认同)

Raf*_*gan 7

您也可以使用此宏将描述分配给参数和 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
Run Code Online (Sandbox Code Playgroud)

感谢Kendall这里的原始帖子。对于UDF 类别


Fis*_*her 5

@will 的方法是最好的。对于像我这样以前没有使用 ExcelDNA 的人,只需添加几行有关详细信息的行。

https://github.com/Excel-DNA/IntelliSense/releases下载 Excel-DNA IntelliSense

有两个版本,一个是64位的,查看你的Excel版本。就我而言,我使用的是 64 版本。

打开 Excel/Developer/Add-Ins/Browse 并选择 ExcelDna.IntelliSense64.xll。

插入一张新表,将名称更改为“ IntelliSense ”,添加功能描述,如https://github.com/Excel-DNA/IntelliSense/wiki/Getting-Started

那就享受吧!:)

在此处输入图片说明