关于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.
关于XLL加载项动态加载、卸载的演示及XLL函数自定义类型注册的演示的更多相关文章
- 动态库DLL加载方式-静态加载和动态加载
静态加载: 如果你有a.dll和a.lib,两个文件都有的话可以用静态加载的方式: message函数的声明你应该知道吧,把它的声明和下面的语句写到一个头文件中 #pragma comment(lib ...
- JAVA反射机制--静态加载与动态加载
Java反射是Java被视为动态(或准动态)语言的一个关键性质.这个机制允许程序在运行时透过Reflection APIs取得任何一个已知名称的class的内部信息,包括其modifiers(诸如pu ...
- Lodop 动态加载模板,动态加载数据
最近需要使用Lodop打印控件,所以就研究了一下,期间从网上找了诸多的东西,基本全是对HTML进行打印的,没有找到我想要的,就只好自己动手丰衣足食. 这篇文章主要讲述的是Lodop与数据的结合使用,官 ...
- JAVA类的静态加载和动态加载以及NoClassDefFoundError和ClassNotFoundException
我们都知道Java初始化一个类的时候可以用new 操作符来初始化, 也可通过Class.forName()的方式来得到一个Class类型的实例,然后通过这个Class类型的实例的newInstance ...
- 使用js加载器动态加载外部Javascript文件
原文:http://www.cnblogs.com/xdp-gacl/p/3927417.html 今天在网上找到了一个可以动态加载js文件的js加载器,具体代码如下: JsLoader.js var ...
- 动态链接库dll的 静态加载 与 动态加载
dll 两种链接方式 : 动态链接和静态链接(链接亦称加载) 动态链接是指在生成可执行文件时不将所有程序用到的函数链接到一个文件,因为有许多函数在操作系统带的dll文件中,当程序运行时直接从操作系统 ...
- JavaScript学习总结(十九)——使用js加载器动态加载外部Javascript文件
今天在网上找到了一个可以动态加载js文件的js加载器,具体代码如下: JsLoader.js 1 var MiniSite=new Object(); 2 /** 3 * 判断浏览器 4 */ 5 M ...
- 使用js加载器动态加载外部js、css文件
let MiniSite = new Object(); /** * 判断浏览器 */ MiniSite.Browser = { ie: /msie/.test(window.navigator.us ...
- 建立WIN32 DLL,并使用静态加载和动态加载
新建工程,选择win32 dll 编写.cpp(或.c) MyDll.cpp #include "windows.h" BOOL APIENTRY DllMain(HANDLE h ...
随机推荐
- ASP.NET -- 一般处理程序ashx
ASP.NET -- 一般处理程序ashx 如果在一个html页面向服务器端请求数据,可用ashx作为后台页面处理数据.ashx适合用作数据后台处理,相当于WebForm中的aspx.cs文件或 ...
- LeetCode算法题-Add Strings(Java实现)
这是悦乐书的第223次更新,第236篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第90题(顺位题号是415).给定两个非负整数num1和num2表示为字符串,返回num ...
- LeetCode算法题-Climbing Stairs(Java实现)
这是悦乐书的第159次更新,第161篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第18题(顺位题号是70).你正在爬楼梯,它需要n步才能达到顶峰.每次你可以爬1或2步, ...
- CSS多行文本垂直居中
今天需要将文本垂直居中,就是一行是垂直居中,多行也是垂直居中. 效果如下 实现代码(同事提供) <!DOCTYPE html> <html> <head lang=&qu ...
- Boolean类型在EF和MySql中的映射关系
MySQL没有Boolean类型.这也是比较奇怪的现象.例: create table xs ( id int primary key, bl boolean ) 这样是可以创建成功,但查看一下建表后 ...
- docker1.13.1的安装与卸载及mysql5.5安装实例
docker中国官方地址:https://www.docker-cn.com/ 您可以使用以下命令直接从该镜像加速地址进行拉取: $ docker pull registry.docker-cn.co ...
- 思考与算法:大脑是cpu、思考是算法
思考与算法:大脑是cpu.思考是算法
- public private protected default
public private protected default 这几个限定访问控制符只是在编译阶段起作用,在运行阶段不起作用 private修饰符 , 本类可以访问 default修饰符 , 本类, ...
- UVA1627-Team them up!(二分图判断+动态规划)
Problem UVA1627-Team them up! Total Submissions:1228 Solved:139 Time Limit: 3000 mSec Problem Descr ...
- [Python] timeit测试代码运行效率
python中有两种方法判断一个数是不是偶数或者奇数: In [29]: 3&1 Out[29]: 1 In [30]: 3%2 Out[30]: 1 In [31]: 4&1 Out ...