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

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

  1. 静态链接库(LIB)和动态链接库(DLL),DLL的静态加载和动态加载,两种LIB文件。

    静态链接库(LIB)和动态链接库(DLL),DLL的静态加载和动态加载,两种LIB文件. 一. 静态链接库(LIB,也简称"静态库")与动态链接库(DLL,也简称"动态库 ...

  2. cwyw不是有效的加载项_EndNote加载项无法显示怎么办?

    似乎X7/X8/X9都可能出现相关的问题,就是WORD里面的EndNote插件选择了但是加载不出来,或者干脆加载项里面就没有,以下是"可能"的一种解决办法.(还有一种一点加载项就崩 ...

  3. Lodop 动态加载模板,动态加载数据

    最近需要使用Lodop打印控件,所以就研究了一下,期间从网上找了诸多的东西,基本全是对HTML进行打印的,没有找到我想要的,就只好自己动手,丰衣足食. 这篇文章主要讲述的是Lodop与数据的结合使用, ...

  4. php动态加载js,动态加载script文件的两种方法_javascript技巧

    动态加载script到页面大约有俩方法 第一种就是利用ajax方式,把script文件代码从后台加载到前台,然后对加载到的内容通过eval()执行代码.第二种是,动态创建一个script标签,设置其s ...

  5. 动态加载___import__动态加载技术

    __import__ 可以实现模块的动态加载,Python中很多框架都使用了这种能力,如Flask的插件系统.APScheduler定时任务框架等. 这里简单看一下APScheduler定时任务框架是 ...

  6. Vue 路由懒加载和动态加载

    什么是路由懒加载? 不同组件有不同的 js 文件,当访问相应组件的时候才会加载其相应的js文件,而不是在首页统一加载,这样就优化了首页渲染的时间,提高页面首次渲染时间: 路由懒加载的原理? 底层是一个 ...

  7. 关于apk加壳之动态加载dex文件

    由于自己之前做了一个关于手机令牌的APK软件,在实现的过程中尽管使用了native so进行一定的逻辑算法保护,但是在自己逆向破解的过程中发现我的手机令牌关键数据能够"轻易地"暴露 ...

  8. wps2019数据分析加载项_WPS加载项——集成创新 体验升级

    在政企的各种业务中,文档作为一种高价值密度的信息载体,文档的全生命周期管理是用户自身和各类业务系统都必须关注的.尤其在当前信创快速推进的大背景下,对业务厂商和文档管理服务商都提出了不小的挑战.从政策角 ...

  9. java 加载shellcode_动态加载 ShellCode绕过杀软

    反病毒解决方案用于检测恶意文件,并且通常使用静态分析技术来区分二进制文件的好坏.如果是恶意文件本身包含恶意内容(ShellCode),那么依靠静态分析技术会非常有效,但如果攻击者使用轻量级的stage ...

最新文章

  1. “雾霾”天里坐看云起时-【软件和信息服务】2014.01
  2. DISK 100% BUSY,谁造成的?(ok)
  3. Android开发概要记录
  4. Django中ORM之或语句查询
  5. 详解NLP技术中的:预训练模型、图神经网络、模型压缩、知识图谱
  6. JavaScript随机排序算法1
  7. 山东科技大学计算机基础知识,山东科技大学_计算机操作系统试题
  8. 火电厂( 4×300MW )电气主系统方案与设备配置初步设计
  9. 如何加声调口诀_拼音声调怎么标口诀
  10. (十二:2020.08.28)CVPR 2016 追踪之论文纲要(译)
  11. 17-chan原理1-创建
  12. Python爬虫之头条采集免费方法
  13. opencv图像形态学运算
  14. 小学生python编程教程-小学生python编程在线教育-小码精灵编程线上教育机构
  15. C++11新特性之long long类型
  16. android7.1root工具,Android模拟器Root,Android7.1.1
  17. 郭晶晶儿子近照曝光 霍启刚澄清怀二胎传闻
  18. win10网络和internet设置没有wlan选项
  19. 共发射极放大电路---工作
  20. PYNQ-Z2 开发板

热门文章

  1. php实现批量上传微信小程序(在windows系统上实现)
  2. 啤酒行业实施ERP案例
  3. 哈尔滨工业大学2021计算机考研大纲,哈尔滨工业大学土木工程学院2021年硕士研究生入学考试大纲...
  4. 我的金工实习心得(三):铸工第二天
  5. 线上基础问题排查常用手册
  6. 第一次刷机,MOTO MB300 平刷2.3
  7. Jbuilder 9.0光标错位问题
  8. 拥有“读心术”是一种怎样的体验?
  9. 揭秘先进制造业如何使用机械行业ERP系统快速升级?
  10. 福建省2021高职高考成绩查询,2021福建高职专科大专录取结果查询和录取通知书发放时间...