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.

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

  1. 动态库DLL加载方式-静态加载和动态加载

    静态加载: 如果你有a.dll和a.lib,两个文件都有的话可以用静态加载的方式: message函数的声明你应该知道吧,把它的声明和下面的语句写到一个头文件中 #pragma comment(lib ...

  2. JAVA反射机制--静态加载与动态加载

    Java反射是Java被视为动态(或准动态)语言的一个关键性质.这个机制允许程序在运行时透过Reflection APIs取得任何一个已知名称的class的内部信息,包括其modifiers(诸如pu ...

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

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

  4. JAVA类的静态加载和动态加载以及NoClassDefFoundError和ClassNotFoundException

    我们都知道Java初始化一个类的时候可以用new 操作符来初始化, 也可通过Class.forName()的方式来得到一个Class类型的实例,然后通过这个Class类型的实例的newInstance ...

  5. 使用js加载器动态加载外部Javascript文件

    原文:http://www.cnblogs.com/xdp-gacl/p/3927417.html 今天在网上找到了一个可以动态加载js文件的js加载器,具体代码如下: JsLoader.js var ...

  6. 动态链接库dll的 静态加载 与 动态加载

    dll 两种链接方式  : 动态链接和静态链接(链接亦称加载) 动态链接是指在生成可执行文件时不将所有程序用到的函数链接到一个文件,因为有许多函数在操作系统带的dll文件中,当程序运行时直接从操作系统 ...

  7. JavaScript学习总结(十九)——使用js加载器动态加载外部Javascript文件

    今天在网上找到了一个可以动态加载js文件的js加载器,具体代码如下: JsLoader.js 1 var MiniSite=new Object(); 2 /** 3 * 判断浏览器 4 */ 5 M ...

  8. 使用js加载器动态加载外部js、css文件

    let MiniSite = new Object(); /** * 判断浏览器 */ MiniSite.Browser = { ie: /msie/.test(window.navigator.us ...

  9. 建立WIN32 DLL,并使用静态加载和动态加载

    新建工程,选择win32 dll 编写.cpp(或.c) MyDll.cpp #include "windows.h" BOOL APIENTRY DllMain(HANDLE h ...

随机推荐

  1. sqli-labs安装

      平台:Win7 SP1     需要准备的东西:   1. Sqli-labs ,下载地址: https://github.com/Audi-1/sqli-labs   2.phpstudy   ...

  2. 第七章 LED将为我闪烁:控制发光二级管

    LED驱动开发实验 如图所示,LED1-LED2 分别与GPC0_3.GPC0_4 相连,通过GPC0_3.GPC0_4 引脚的高低电平来控制三极管的导通性,从而控制LED 的亮灭. 根据三极管的特性 ...

  3. Fetch请求后台的数据

    <style> #btn{ width: 50px; height: 50px; background-color: red; } #output{ width: 100px; heigh ...

  4. 【Linux基础】awk命令

    1.awk命令说明 (1)awk是行处理器: 相比较屏幕处理的优点,在处理庞大文件时不会出现内存溢出或是处理缓慢的问题,通常用来格式化文本信息 (2)awk处理过程:  依次对每一行进行处理,然后输出 ...

  5. 常用Dockerfile举例

    FROM ubuntu:14.04 MAINTAINER sss ENV JAVA_HOME /opt/jdk RUN \ echo 'export PATH=$JAVA_HOME/bin:$PATH ...

  6. UEditor学习笔记1

    首先对于前段时间遇到的一些总结做下记录: 0 == ''  => true transition,渐变属性,其值可以是某属性,也可以是all,如transition: all 0.3s:鼠标放到 ...

  7. [matlab] 18.图与网络 (转载)

    基本概念: 图论[Graph Theory]是数学的一个分支.它以图为研究对象.图论中的图是由若干给定的点及连接两点的线所构成的图形,这种图形通常用来描述某些事物之间的某种特定关系,用点代表事物,用连 ...

  8. 深度学习之Attention Model(注意力模型)

    1.Attention Model 概述 深度学习里的Attention model其实模拟的是人脑的注意力模型,举个例子来说,当我们观赏一幅画时,虽然我们可以看到整幅画的全貌,但是在我们深入仔细地观 ...

  9. 02 python初学 (数字运算 逻辑运算)

    运算: 5/2 -> 2.5 5//2 -> 2  取整 5%2 -> 1  取余 2**10 -> 1024 指数运算 逻辑运算符: and : 条件1 and 条件2 no ...

  10. js同步-异步-回调

    出处:https://blog.csdn.net/u010297791/article/details/71158212(1)上面主要讲了同步和回调执行顺序的问题,接着我就举一个包含同步.异步.回调的 ...