关于XLL加载项动态加载、卸载的演示及XLL函数自定义类型注册的演示

1、在XLL中,把函数定义成不同的类型,在Excel中的实际效果也不同,具体如下:

pxMacroType value                                                           0     1      2
  Can be called from a worksheet                                      Yes    Yes      No
  Can be called from a macro sheet                                   Yes    Yes     Yes
  Can be called from a defined name definition                    Yes    Yes     Yes
  Can be called from a conditional format expression           Yes    Yes   No
  Listed in the Function Wizard for worksheet functions        No    Yes   No
  Listed in the Function Wizard for macro sheet functions     No    Yes  Yes

 

注册函数需要使用Excel4的xlfRegister参数,其参数说明如下:

pxModuleText XLL名字,可以通过xlGetName获取
pxProcedure  推荐使用字符串,表示在XLL 代码中的函数名
pxTypeText   表示函数参数的类型和函数返回值的类型,字符串
pxFunctionText 函数名,在Excel中显示的名称
pxArgumentText 参数描述字符串
pxMacroType    函数类型: 0,1,2
pxCategory      函数类别
pxShortcutText  命令(类型2)的快捷键,"A" assigns this command to CONTROL+SHIFT+A
pxHelpTopic     帮助的引用字符串
pxFunctionHelp  函数向导中的描述
pxArgumentHelp1 函数参数1描述,后面依次类推

为了直观看到不同函数类型的效果,我用ExcelDna做了个演示文件,在文件中实现了XLL的加载、卸载;函数的注册、反注册等功能。

由于ExcelDna的限制,直接使用xlfRegister更改函数类型,会造成返回值的错误。因此,例子中的MySub函数返回值无意义。

                           工作表函数向导                                                                       宏表函数向导

 2、XLL可以通过另一个XLL进行加载和卸载,在Excel开发里面,这是最方便的升级方式。把俺的DNATool.XLL放到同一目录下,通过加载项里面的菜单可以加载。注意名字必须完全一致,俺的代码只认识这个名字 :)

     

 

 

文件下载   TestXllFunction

 

有什么建议欢迎联系QQ:564955427

 

 ************************************************

Conditional Formatting Formulas Must Have References - If you have a conditional formatting formula that references a UDF defined in another workbook such as an add-in, then you must add a Reference to that workbook before you can reliably use the functions defined in it.  If you don't, you will (sometimes) get the error 'This type of reference cannot be used in a Conditional Formatting Formula'. To add a reference, press Alt+F11 to go to the code editor, then go to Tools, References, and add the reference to this workbook by project name for the project containing the VBA code you need.

 

条件格式里面只能使用工作簿本身的公式,或者在VBE中引用的xla、xlsm等文件里面的公式。加载宏即使已经加载,但没有引用的话,依然不能在条件格式的公式里面使用。

 

 ************************************************

http://msdn.microsoft.com/en-us/library/bb687858.aspx   Accessing XLL Code in Excel

Calling XLL Functions Directly from Excel
Once they are registered, XLL worksheet and macro sheet functions can be called from anywhere a built-in function can be called from:
    A single-cell or array formula on a worksheet.
    A single-cell or array formula on a macro sheet.
    The definition of a defined name.
    The condition and limit fields in a conditional format dialog box.
    From another add-in via the C API function xlUDF.
    From Visual Basic for Applications (VBA) via the Application.Run method.

You can obtain a reference to the calling cell or range of cells within your function using the C API function xlfCaller. If the function was called from the cell’s conditional format expression, you are still returned a reference to the associated cell or cells, so you cannot assume that the cell’s formula contains the XLL function. If your function was called from a VBA user-defined function (UDF), xlfCaller again returns the address of the cells that called the VBA function. For more information, see xlfCaller.

 

Registering Functions and Commands with Excel
Registration tells Excel the following about a DLL entry point:
    Whether it is hidden or, if a function, whether it is visible in the Function Wizard.
    Whether it is callable only from an XLM macro sheet, or also from a worksheet.
    If a command, whether it is a worksheet function or a macro sheet equivalent function.
    What its XLL/DLL export name is, and what name you want Excel to use.
    If it is a function:
        What data types it returns and takes as arguments.
        Whether it returns its result by modifying an argument in place.
        Whether it is volatile.
        Whether it is thread safe (supported starting in Excel 2007).
        What text the Paste Function Wizard and AutoComplete editor should display to help with calling the function.
        Which function category it should be listed under.
This is all achieved using the C API function xlfRegister, equivalent to the XLM function REGISTER.

转载于:https://www.cnblogs.com/Charltsing/p/TestXllUDF.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Excel XLL(Excel eXtension Language Library)是一种用于开发Excel插件的编程语言,它可以扩展Excel的功能并增加自定义函数和工具。 使用Excel XLL开发可以实现以下几个方面的功能: 1. 自定义函数:通过Excel XLL,可以开发自定义函数,使其可以在Excel中像内置函数一样行使用。这为用户提供了更多的数据计算和分析选。 2. 数据处理:Excel XLL提供了强大的数据处理功能,开发者可以通过它来实现更复杂的数据分析和处理逻辑,例如数据筛选、排序、转置等。 3. 用户界面:Excel XLL还可以用于开发自定义的用户界面,以实现更复杂的交互逻辑和用户体验。通过这些自定义界面,用户可以更方便地行数据输入、操作和结果查看。 4. 数据连接:Excel XLL也可以被用于数据连接,将Excel与其他数据源(如数据库、Web服务等)行连接,方便数据的导入和导出,以及实现实时数据更新功能。 相比于Excel宏编程,Excel XLL开发具有更高的性能和更丰富的功能选。通过使用Excel XLL,可以更灵活地控制数据计算和处理逻辑,并提供更好的用户交互体验。同时,Excel XLL还支持跨平台的使用,可以在不同的操作系统和Excel版本中行开发和使用。 总之,Excel XLL开发是一种非常强大和灵活的Excel插件开发方式,可以为用户提供更多的功能和选,满足各种数据处理和分析的需求。它的使用也可以提高工作效率和准确性,同时提升Excel应用的整体体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值