|
本帖最后由 lss001 于 2017-7-11 12:49 编辑
Function TiXing_mianji(ByVal a As Long, ByVal b As Long, _
ByVal h As Long) As Long '已知长宽高返回梯形面积自定义函数-该代码放在加载宏模块中
TiXing_mianji = (a + b) * h / 2
End Function
Public Sub RegisterUDF(ByVal FunctionName As String, ByVal Category As String, _
ByVal Des As String, ByVal Args As String, ByVal DesArgs As String) '注册函数-该代码放在加载宏模块中
Application.ExecuteExcel4Macro _ "REGISTER(""C:\Windows\System32\user32.dll"",""CharPrevA"",""P#"",""" _
& FunctionName & """,""" & Args & """,1" _
& ",""" & Category & """,,,""" & Des & """," & DesArgs & ")"
End Sub
Sub Workbook_Open()'自定义函数参数说明-该代码放在加载宏ThisWorkbook中
x1 = "TiXing_mianji" '函数名称
x2 = "数学与三角函数" '函数类型(类型可自定义)
x3 = "返回梯形面积" '函数说明
y1 = "长度" '函数参数1
y2 = "宽度" '函数参数2
y3 = "高度" '函数参数3(参数可增可减)
z1 = "单位: 米" '函数参数1说明
z2 = "单位: 米" '函数参数2说明
z3 = "单位: 米 " '函数参数3说明(参数说明可增可减),最后一个函数参数说明右边应留空" "
Call RegisterUDF(FunctionName:="" & x1 & "", _
Category:="" & x2 & "", Des:="" & x3 & "", _
Args:="" & y1 & "," & y2 & "," & y3 & "", _
DesArgs:="""" & z1 & """,""" & z2 & """,""" & z3 & """")
End Sub |
|