识别除了其名称之外的工作表

编程入门 行业动态 更新时间:2024-10-27 03:26:59
本文介绍了识别除了其名称之外的工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

工作表可以通过其名称来标识,例如:

A worksheet can be identified by its name such as in this example:

Dim mysheet As Worksheet Set mysheet = ThisWorkbook.Sheets("My Sheetname")

现在我想知道工作表是否可以被识别其他比起它的名字,例如通过一些唯一的id或某些属性或任何东西。

Now I wonder if a worksheet can be identified other than by its name, for example by some unique id or some property or whatever.

我的问题是:

参考上面的代码片段:如果用户更改了工作表的名称(例如从我的工作表到您的工作表),则该代码片段显然将无法工作。

Referring to the code snippet above: if a user changes the name of the worksheet (e.g. from "My Sheetname" to "Your Sheetname"), the snippet obviously won't work anymore.

推荐答案

这是一个非常好的文章,解释说最好使用 SheetID (也称为codename),而不是

This is a very good article that explains that it is better to use the SheetID (also called codename) instead of the Sheet Name.

报价:

代号p roperty是Excel用于标识每个表的内部名称。不同于Worksheet.Name属性,代码名称保持相同,无论工作表名称或工作表顺序。

The Codename property is the internal name that Excel uses to identify each sheet. Unlike the Worksheet.Name property, the Codename remains the same regardless of sheet name, or sheet order.

代码名称也可以更改,以便它更具描述性:

The code name can also be changed so that it is more descriptive:

ThisWorkbook.VBProject.VBComponents("Sheet1").Name = "Revenue_Actuals"

然后

Revenue_Actuals.Range("C2").value = 10

使用代号(例如 Sheet1.Range(C1)。value )是一个好主意,然而,如上所述,在运行时更改代码名称​​不被认为是一些开发人员的好习惯(参见例如对上面链接的文章的评论)。

Using codenames (such as Sheet1.Range("C1").value) is a good idea, however changing code names at runtime as above is not considered good practice by some developers (see for example, comments on the article of the link above).

使用表单索引是另一种方式,但我个人更喜欢代码名称。

Using the sheet index is another way to go, but I personally prefer the code name.

最后, this a

Finally, this article lists many ways that a sheet or workbook can be referenced.

希望这有帮助!

更多推荐

识别除了其名称之外的工作表

本文发布于:2023-10-26 08:06:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529581.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:名称   工作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!