ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 45262|回复: 65

如何给自定义函数的参数添加描述信息?

[复制链接]

TA的精华主题

TA的得分主题

发表于 2003-9-16 10:57 | 显示全部楼层 |阅读模式
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
本帖已被收录到知识树中,索引项:自定义函数开发
The description of this function is truncated in the SDK. The authors have kept the
definition of the FIRST xlfRegister function (the one of EXCEL 4!!!) and they don't have
updated it, whereas the new xlfRegister function (Excel 5 and above) supports more
arguments. With these new arguments, you can pass to xlfRegister a description string
for each parameter of your UDF, which will be displayed by the function wizard.

If you want to get a complete description of xlfRegister, open the file "Macrofun.hlp"
(directory "xlm" in the CD-ROM provided with the SDK), and search the topic REGISTER.

Here is an example of a complete UDF registration which I have used recently. This
"ESPERVIE" function calculates an "esperance de vie" (life expectancy). It returns a
pointer to an OPER structure and is based on four arguments : two FP structures (type
"K") and two OPERs (type "P"). The five last parameters passed to xlfRegister, displayed
by the function wizard, describe the function and each of its arguments.
When the user selects ESPERVIE in the function wizard and calls the help, it opens the
help file "Mortalit.hlp" and activates the help topic number 0.

  1. Excel(xlfRegister,0,14,&xModuleText,TempStr(" Espervie"),
  2. TempStr(" PKKPP"),TempStr(" ESPERVIE"),TempStr(" Deces,Pop,Age,Annees"),
  3. TempNum(1),TempStr(" Indicateurs de mortalitй"),TempMissing(),
  4. TempStr(" C:\\Program Files\\XLLs\\Mortalit.hlp!0"),
  5. TempStr(" Calcule une espйrance de vie"),
  6. TempStr(" Effectifs cumulйs de dйcиs par classes d'вge (en 5)"),
  7. TempStr(" Population par classes d'вge quinquennales"),
  8. TempStr(" Age de base (par dйfaut : 0)"),
  9. TempStr(" Nombre d'annйes de dйcиs (par dйfaut : 1) "));
复制代码
Another advice : avoid the XLOPER arguments (type "R") in your user defined functions;
if you just want to get the passed values and no range references, use rather OPER
arguments ("P"). Two reasons for this : when a XLOPER structure refers to a cell
containing the RAND() function, trying to coerce this XLOPER can either return a zero if
the structure contains a single value, or entail a GPF if it contains an array (at least
in Excel 97).
I don't know if this bug has been corrected by the SR1. It arises even if you do a
xlRetUncalced test. And with OPER structures you don't have to use xlCoerce at all
(Excel does it automatically before calling the function).

[ 本帖最后由 taller 于 2008-11-16 13:30 编辑 ]

TA的精华主题

TA的得分主题

 楼主| 发表于 2003-9-21 09:08 | 显示全部楼层
另一种更好的方法:


This example shows how to register functions into user-defined catagories and
provide descriptions for their arguments. The Auto_Open procedure registers
the two functions, Multiply and Divide in two categories Multiplication and
Division and provides descriptions of the input parameters.

  1. Const Lib = """c:\windows\system\user32.dll"""
  2. Option Base 1

  3. Private Function Multiply(N1 As Double, N2 As Double) As Double
  4.   Multiply = N1 * N2
  5. End Function

  6. '==========================================

  7. Private Function Divide(N1 As Double, N2 As Double) As Double
  8.   Divide = N1 / N2
  9. End Function

  10. '==========================================

  11. Sub Auto_open()

  12.   Register "DIVIDE", 3, "Numerator,Divisor", 1, "Division", _
  13.     "Divides two numbers", """Numerator"",""Divisor """, "CharPrevA"
  14.   Register "MULTIPLY", 3, "Number1,Number2", 1, "Multiplication", _
  15.     "Multiplies two numbers", """First number"",""Second number """, _
  16.     "CharNextA"

  17. End Sub

  18. '==========================================

  19. Sub Register(FunctionName As String, NbArgs As Integer, _
  20.   Args As String, MacroType As Integer, Category As String, _
  21.   Descr As String, DescrArgs As String, FLib As String)
  22.   
  23.   Application.ExecuteExcel4Macro _
  24.   "REGISTER(" & Lib & ",""" & FLib & """,""" & String(NbArgs, "P") _
  25.   & """,""" & FunctionName & """,""" & Args & """," & MacroType _
  26.   & ",""" & Category & """,,,""" & Descr & """," & DescrArgs & ")"

  27. End Sub

  28. '==========================================

  29. Sub Auto_close()
  30.   
  31.   Dim FName, FLib
  32.   Dim I As Integer
  33.   FName = Array("DIVIDE", "MULTIPLY")
  34.   FLib = Array("CharPrevA", "CharNextA")
  35.   For I = 1 To 2
  36.     With Application
  37.       .ExecuteExcel4Macro "UNREGISTER(" & FName(I) & ")"
  38.       .ExecuteExcel4Macro "REGISTER(" & Lib & _
  39.         ",""CharPrevA"",""P"",""" & FName(I) & """,,0)"
  40.       .ExecuteExcel4Macro "UNREGISTER(" & FName(I) & ")"
  41.     End With
  42.   Next
  43.   
  44. End Sub
复制代码

[ 本帖最后由 taller 于 2008-11-16 13:30 编辑 ]

TA的精华主题

TA的得分主题

发表于 2003-9-21 11:51 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2003-9-21 14:08 | 显示全部楼层
你是在练英文吗 不是的话 那你练练汉语吧,我想这个论坛识汉语的人多的

TA的精华主题

TA的得分主题

 楼主| 发表于 2003-9-22 11:15 | 显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用  · 内置多项VBA编程加强工具       ★ 免费下载 ★      ★使用手册
我从老外的网上找来贴出,未来得及翻译和理解!

TA的精华主题

TA的得分主题

 楼主| 发表于 2003-9-22 11:20 | 显示全部楼层
对于第一篇文章的内容,我未能理解! 对于第二篇文章的内容,我已经运用到我的程序中! 要点:要注意函数名称的大小写!

TA的精华主题

TA的得分主题

发表于 2003-9-22 14:45 | 显示全部楼层
我的为何只能注册两个 我总共注了7个 可是在选择的时候函数时 最后一个"CharPrevA"各"CharNextA"有效,参数等都是这两个的 那么在REGISTER中FLib该如何取值 我的系统为OFFICE2000+WINXP

TA的精华主题

TA的得分主题

发表于 2003-9-22 16:27 | 显示全部楼层
以下是引用SCYANGYU在2003-9-22 11:20:00的发言: 对于第一篇文章的内容,我未能理解! 对于第二篇文章的内容,我已经运用到我的程序中! 要点:要注意函数名称的大小写!
REGISTER的最后一个参数 为什么只能添加2个 第三,第四......第N个该用何参数

TA的精华主题

TA的得分主题

 楼主| 发表于 2003-10-7 08:22 | 显示全部楼层
实际上,我用的是我自己的DLL! Const Lib = """IFCSW67.dll""" Sub Auto_open() Register "Fun1", 3, "Numerator,Divisor", 1, "Division", _ "Divides two numbers", """Numerator"",""Divisor """, "F1" Register "Fun2", 3, "Number1,Number2", 1, "Multiplication", _ "Multiplies two numbers", """First number"",""Second number """, _ "F2" Register "Fun3", 3, "Numerator,Divisor", 1, "Division", _ "Divides two numbers", """Numerator"",""Divisor """, "F3" Register "Fun4", 3, "Number1,Number2", 1, "Multiplication", _ "Multiplies two numbers", """First number"",""Second number """, _ "F4" Register "Fun5", 3, "Numerator,Divisor", 1, "Division", _ "Divides two numbers", """Numerator"",""Divisor """, "F5" Register "Fun6", 3, "Number1,Number2", 1, "Multiplication", _ "Multiplies two numbers", """First number"",""Second number """, _ "F6" Register "Fun7", 3, "Numerator,Divisor", 1, "Division", _ "Divides two numbers", """Numerator"",""Divisor """, "F7" End Sub Sub Auto_close() Dim FName, FLib Dim I As Integer FName = Array("Fun1", "Fun2", "Fun3", "Fun4", "Fun5", "Fun6", "Fun7") FLib = Array("F1", "F2", "F3", "F4", "F5", "F6", "F7") For I = 1 To 7 With Application .ExecuteExcel4Macro "UNREGISTER(" & FName(I) & ")" .ExecuteExcel4Macro "REGISTER(" & Lib & _ ",""CharPrevA"",""P"",""" & FName(I) & """,,0)" .ExecuteExcel4Macro "UNREGISTER(" & FName(I) & ")" End With Next End Sub

TA的精华主题

TA的得分主题

发表于 2003-10-7 08:41 | 显示全部楼层
那么你将函数也放在自己的DLL!中了吗?你用什么工具来制作的DLL
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-5-1 16:41 , Processed in 0.046743 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表