简体   繁体   中英

Excel unique worksheet name

How can I select worksheet in excel using vba even when sheet name and sheet position changed constantly?

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.

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?

Thank you

You can use Name in VBE to specify your name for Worksheet. This will allow you to rename your Worksheet in Excel according to your needs.

In VBA you can then use something like:

Option Explicit

Sub Test()

MyWorksheetName.Activate

End Sub

This is where you edit your Name:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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