使用宏时VBA ListObject的命名规则不一致(在结尾处加下划线) [英] VBA ListObject inconsistent naming rules when using a macro (puts underscores at endings)
问题描述
您可以将表命名为"my000",但不能将其命名为"my001".您也不能将其命名为"bab002","lal0101"或类似名称.
You can name your table "my000" but you can't name it "my001". You also can't name it "bab002", "lal0101" or anything similar.
在使用宏创建和重命名表时,我注意到有时有时会在无正当理由的情况下在表名的末尾加下划线(例如myt001). Excel提示名称不应与现有名称冲突,以数字开头或包含空格或不允许的字符.我尝试使用的名称似乎完全正确,例如,通过Excel将其更改为"my001_",从而破坏了电子表格的其他部分.
When using macros to create and rename tables I noticed that sometimes it puts underscore at the end of the table name (like myt001) with no valid reason. Excel prompts that a name should not be in conflict with existing name, start with number or include space or not allowed character. The names that I try seem completely correct, by Excel changes them to for instance to "my001_", disrupting other parts of my spreadsheet.
要重现:打开空白Excel,使用Insert-> table创建一个空表,然后尝试将其命名为"ba001"或类似名称.尝试对vba进行相同操作时,它会在下划线("ba001_")后面加上下划线,而没有理由这样做.
To reproduce: open blank Excel, create an empty table with Insert -> table then try to name it "ba001" or something similar. When trying to do the same with vba, it puts underscore at the end ("ba001_"), having no reason to do this.
我希望vba为ListObjects提供(应该是)正确的名称.而是在意外情况下在结尾处加下划线.
I expect vba to give the (supposedly) correct names to ListObjects. Instead it puts underscores at the endings in unexpected situations.
推荐答案
基于Mikku& Maeaex1说,表名的命名约定使vba忽略名称字符串中的"00",从而使vba引用单元格"BAB001".
The conclusion based on what Mikku & Maeaex1 said, the table name is named in a convention that makes vba reference a cell "BAB001" due to ignoring the "00" within the name string.
解决方案:更改与Excel的单元格命名约定不一致的命名约定,例如以下划线"_"开头的表名字符串,这也将给您带来更多的好处,即在您启动和键入时在excel中引用它时, "= _"将显示所有表和命名范围的列表,而不是其他以相同字母开头的函数.
Solution: change naming convention that is not consistent with Excel's cell naming convention, such as starting the table name string with an underscore " _ " which will also give the added benefit of when you reference it within excel when you start and type "=_" a list of all your tables and named range will appear instead of other functions that start with the same letters.
这篇关于使用宏时VBA ListObject的命名规则不一致(在结尾处加下划线)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!