为什么单字母 UDF 名称不能使用 C 或 R? [英] Why can't a single-letter UDF name use C or R?

查看:35
本文介绍了为什么单字母 UDF 名称不能使用 C 或 R?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以编写以下有效的 VBA 函数:

I can write the following valid VBA functions:

Public Function C() As Long
  C = 5
End Function

Public Function R() As Long
  R = 6
End Function

但我不能在 Excel 公式中使用它们,除非用 VBA 项目或模块名称限定它们.

But I can't use them in an Excel formula, without qualifying them with the VBA project or module name.

FWIW、Function NFunction T 也是有效的,但它们与内置函数发生冲突.

FWIW, Function N and Function T are valid too, but they clash with built-in functions.

认为 CR 必须是 Excel 公式中的保留名称,但我不明白为什么.任何将 C/R 用作函数调用都可以解析为函数调用,因为它们后面会紧跟一个 (,而任何使用C/R 作为 R1C1 符号不会紧跟在 (.

I think C and R must be reserved names in Excel formulas, but I don't understand why. Any use of C/R as function calls would be parseable as function calls because they would be immediately followed by a (, whereas any use of C/R as R1C1 notation would not be immediately followed by a (.

有趣的是,如果我用项目和/或模块的名称限定函数调用,我就可以调用这些函数:

Interstingly, I can call the functions if I qualify the function call with the name of the project and/or module:

=VBAProject.C()
5

=Module1.C()
5

=VBAProject.Module1.C()
5

推荐答案

来自 微软文档:

提示:不能使用大写和小写字符C"、c"、"R" 或 "r" 作为定义的名称,因为它们都用作为当前选定的行选择行或列的简写当您在名称"或转到"文本框中输入它们时.

Tip: You cannot use the uppercase and lowercase characters "C", "c", "R", or "r" as a defined name, because they are all used as a shorthand for selecting a row or column for the currently selected cell when you enter them in a Name or Go To text box.

我知道定义命名范围时的这种限制.显然它也扩展到命名 UDF(这是有道理的).

I was aware of this limitation in defining named ranges. Evidently it extends to naming UDFs as well (which makes sense).

这篇关于为什么单字母 UDF 名称不能使用 C 或 R?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆