电脑教程
位置:首页>> 电脑教程>> office教程>> Excel VBA 添加自定义函数的参数描述

Excel VBA 添加自定义函数的参数描述

  发布时间:2023-08-20 10:48:21 

标签:Excel,VBA,添加,自定义,函数,的,参数,描述,在

Excel 2010 发布之前,用户已经可以为自定义函数(User-Defined Function)添加一系列的信息,比如描述等等。但是无法用常规的手段为自定义函数的参数添加描述信息。Excel 2010 及以后版本这个问题得到了解决。微软改进了 VBA 中 Application 对象的 MacroOptions 方法——在原来的基础上添加了一个 ArgumentDescriptions 参数,利用此参数就可以为用户自定义函数添加描述信息了。以下给出一个具体例子来说明这个方法的具体应用,将后列的代码复制到一个标准模块中,然后执行其中的 RegUDF 过程,你就可以在 Excel 中使用‍ FunArgDes 函数了

Excel VBA 添加自定义函数的参数描述

具体代码:

'用户自定义函数
Function FunArgDes(int1 As Integer, int2 As Integer) As Integer
FunArgDes = int1 + int2
End Function

'此过程用户注册自定义函数
Sub RegUDF()
Dim FuncName As String '函数名称
Dim FuncDesc As String '函数描述
Dim Category As String '函数类别
Dim ArgDesc(1) As String '函数参数描述数组
FuncName = "FunArgDes"
FuncDesc = "返回两个整数的和(测试函数参数描述)"
Category = "函数参数描述测试"
ArgDesc(0) = "函数参数第一个,整型"
ArgDesc(1) = "函数参数第二个,整型"
Call Application.MacroOptions(Macro:=FuncName, Description:=FuncDesc, Category:=Category, ArgumentDescriptions:=ArgDesc)
End Sub

Excel VBA 添加自定义函数的参数描述的下载地址:


     

0
投稿

猜你喜欢

手机版 电脑教程 asp之家 www.aspxhome.com