|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
自定义函数的参数添加描述信息
Const Lib = """c:windowssystem32user32.dll"""
Option Base 1
Private Function Multiply(N1 As Double, N2 As Double) As Double
Multiply = N1 * N2
End Function
Private Function Divide(N1 As Double, N2 As Double) As Double
Divide = N1 / N2
End Function
Sub Auto_open()
Register "DIVIDE", 3, "Numerator,Divisor", 1, "Division", _
"Divides two numbers", """Numerator"",""Divisor """, "CharPrevA"
Register "MULTIPLY", 3, "Number1,Number2", 1, "Multiplication", _
"Multiplies two numbers", """First number"",""Second number """, _
"CharNextA"
End Sub
Sub Register(FunctionName As String, NbArgs As Integer, _
Args As String, MacroType As Integer, Category As String, _
Descr As String, DescrArgs As String, FLib As String)
Application.ExecuteExcel4Macro _
"REGISTER(" & Lib & ",""" & FLib & """,""" & String(NbArgs, "P") _
& """,""" & FunctionName & """,""" & Args & """," & MacroType _
& ",""" & Category & """,,,""" & Descr & """," & DescrArgs & ")"
End Sub
Sub Auto_close()
Dim FName, FLib
Dim I As Integer
FName = Array("DIVIDE", "MULTIPLY")
FLib = Array("CharPrevA", "CharNextA")
For I = 1 To 2
With Application
.ExecuteExcel4Macro "UNREGISTER(" & FName(I) & ")"
.ExecuteExcel4Macro "REGISTER(" & Lib & _
",""CharPrevA"",""P"",""" & FName(I) & """,,0)"
.ExecuteExcel4Macro "UNREGISTER(" & FName(I) & ")"
End With
Next
End Sub
使用这个例子可以添加自定义函数说明。
对于xp系统,Const Lib = """c:windowssystem32user32.dll""",其他系统需要找到user32.dll的路径填入。输入代码保存后,需要重启excel改函数才能加入说明
代码原地址:http://www.j-walk.com/ss/excel/eee/eee009.txt
基本原理是利用了Excel4Macro来伪造一个自定义函数同名的dll,使用dll的说明在添加自定义函数的说明,而excel正常调用的函数为自定义函数,参数显示为dll。
国人的一个例子:http://www.excelba.com/Soft/Html/131.html ( 给自定义函数添加说明的示例)
国外的一个例子:http://www.jkp-ads.com/Articles/RegisterUDF00.asp
其他添加自定义函数说明的方法总结:http://hi.baidu.com/%B4%BA%B7%D6 ... a7b6ae6d811925.html |
|