vba 如何在excel-vba中找到重命名的工作表的索引号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19775587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to find the index number of renamed sheets in excel-vba
提问by terence vaughn
I have about 8 sheets in a workbook with different names. Is there a way using VBA to activate one ore more of these sheets based on their index number? For example I have sheets named, "Month", "Name", "Age" etc... how can I find their index number?
我的工作簿中有大约 8 张不同名称的工作表。有没有办法使用 VBA 根据索引号激活这些工作表中的一个或多个?例如,我有名为“月”、“姓名”、“年龄”等的工作表……我如何找到它们的索引号?
回答by Santosh
Try this
尝试这个
Sheets("<sheet Name>").Index
Sheets("<sheet Name>").Index
If you want to get code name
如果你想获得代号
Sheets("<sheet Name>").codename
Sheets("<sheet Name>").codename
It's possible for the sheet name to be different from the code name. When you create a sheet, the sheet name and code name are the same, but changing the sheet name doesn't change the code name, and changing the code name (using the Properties window in the Visual Basic Editor) doesn't change the sheet name.
工作表名称可能与代码名称不同。创建工作表时,工作表名称和代码名称相同,但更改工作表名称不会更改代码名称,更改代码名称(使用 Visual Basic 编辑器中的“属性”窗口)不会更改代码名称工作表名称。
回答by Joe
To get a sheet's index:sheets("month").index
要获取工作表的索引:sheets("month").index
To activate by index:sheets(5).activate
按索引激活:sheets(5).activate