|
Const Lib = """c:\windows\system32\user32.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:\windows\system32\user32.dll""",其他系统需要找到user32.dll的路径填入。输入代码保存后,需要重启excel改函数才能加入说明
代码原地址:http://www.j-walk.com/ss/excel/eee/eee009.txt
基本原理是利用了Excel4Macro来伪造一个自定义函数同名的dll,使用dll的说明在添加自定义函数的说明,而excel正常调用的函数为自定义函数,参数显示为dll。
其他添加自定义函数说明的方法为:http://hi.baidu.com/%B4%BA%B7%D6 ... a7b6ae6d811925.html |
|