简体   繁体   English

Excel 唯一工作表名称

[英]Excel unique worksheet name

How can I select worksheet in excel using vba even when sheet name and sheet position changed constantly?即使工作表名称和工作表位置不断变化,如何使用 vba 在 excel 中选择工作表?

I was using sheet index to avoid vba fail to select worksheet after changing the worksheet name, however, if I change relative position of the ws, its index changes.我使用工作表索引来避免在更改工作表名称后 vba 无法选择工作表,但是,如果我更改 ws 的相对位置,它的索引会发生变化。

I noticed that sheet name in vba project browser, there is a item called (name) which is a fixed sheet number (I guess it was named by the sequence that I created the ws.) Is it possible to select ws based on this fixed name?我注意到 vba 项目浏览器中的工作表名称,有一个名为 (name) 的项目,它是一个固定的工作表编号(我猜它是由我创建 ws 的序列命名的。)是否可以基于此固定选择 ws姓名?

Thank you谢谢

You can use Name in VBE to specify your name for Worksheet.您可以在 VBE 中使用 Name 来指定 Worksheet 的名称。 This will allow you to rename your Worksheet in Excel according to your needs.这将允许您根据需要重命名 Excel 中的工作表。

In VBA you can then use something like:在 VBA 中,您可以使用以下内容:

Option Explicit

Sub Test()

MyWorksheetName.Activate

End Sub

This is where you edit your Name:这是您编辑姓名的地方:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM