从Excel单元格调用Excel工作表函数
我有一组用户定义的 vba 函数,位于 Excel 模块中,然后从 Excel 电子表格中调用这些函数...此时一切工作正常。
我被要求将 vba 从模块移动到工作表的代码页。当我这样做时,我发现我无法从工作表上的单元格调用任何函数......名称根本不显示为现有的。有没有办法从 Excel 单元格调用工作表函数?另外,从另一个模块中的用户定义函数或后面的工作表代码调用工作表函数是否存在任何问题?
编辑:
我发现如果我通过sheetname.functionname调用,它会抛出一条错误消息,其中包括“该名称与Excel内置名称或工作簿中另一个对象的名称冲突”...如果我使用sheetname.anythingelse 它只是解析为#NAME?
这是否意味着不能从工作表中调用 Excel 工作表函数?
I have a set of user defined vba functions that sit in an excel module, which are then called from an excel spreadsheet... everything has worked fine at this point.
I've been asked to move the vba from the module to the worksheet's code page. When I did this, I've found I can't call any of the functions from cells on the worksheet... the names simply don't show as existing. Is there a way to call worksheet functions from an excel cell? Also, is there any problem calling a worksheet function from a user defined function in another module or worksheet code behind?
EDIT:
I've found if I call by the sheetname.functionname, it throws an error message that includes "The name conflicts with an Excel built-in name or the name of another object in the workbook"... where if I use sheetname.anythingelse it just resolves to #NAME?
Does this mean excel worksheet functions cannot be called from a sheet?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不可以。工作表对象中的函数不能作为用户定义函数从工作表中调用。
Worksheet 对象用于响应工作表上发生的事件。您不能将用户定义的函数放在那里。用户定义的函数必须位于模块中。
如果您的用户定义函数确实存在于模块中,那么从其他地方的代码调用它不会有任何问题......包括在工作表“代码隐藏”中。
No. Functions in the worksheet object can't be called from the sheet as user-defined functions.
The Worksheet object is intended for responding to events that happen on a worksheet. You can't put user-defined functions there. User defined functions have to live in a Module.
If your user-defined function does live in a module, you won't have any problem calling it from code anywhere else... including in the worksheet "code-behind".
您必须将代码放入标准模块中。
检查此链接。
http://www.cpearson.com/excel/writingfunctionsinvba.aspx
You have to put the code in a standard module.
Check this link.
http://www.cpearson.com/excel/writingfunctionsinvba.aspx