vba 如何激活 Excel 中的特定工作表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4013792/
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 activate a specific worksheet in Excel?
提问by Alex
I just need to activate a certain worksheet. I have a string variable that keeps the name of the worksheet.
我只需要激活某个工作表。我有一个保留工作表名称的字符串变量。
回答by Dennis G
Would the following Macro help you?
下面的宏对你有帮助吗?
Sub activateSheet(sheetname As String)
'activates sheet of specific name
Worksheets(sheetname).Activate
End Sub
Basically you want to make use of the .Activate function. Or you can use the .Select function like so:
基本上你想使用 .Activate 函数。或者你可以像这样使用 .Select 函数:
Sub activateSheet(sheetname As String)
'selects sheet of specific name
Sheets(sheetname).Select
End Sub
回答by Moreno
I would recommend you to use worksheet's index instead of using worksheet's name, in this way you can also loop through sheets "dynamically"
我建议您使用工作表的索引而不是使用工作表的名称,这样您还可以“动态”循环工作表
for i=1 to thisworkbook.sheets.count
sheets(i).activate
'You can add more code
with activesheet
'Code...
end with
next i
It will also, improve performance.
它还将提高性能。
回答by Daan
An alternative way to (not dynamically) link a text to activate a worksheet without macros is to make the selected string an actual link. You can do this by selecting the cell that contains the text and press CTRL+K then select the option/tab 'Place in this document' and select the tab you want to activate. If you would click the text (that is now a link) the configured sheet will become active/selected.
另一种(非动态)链接文本以激活没有宏的工作表的方法是使所选字符串成为实际链接。您可以通过选择包含文本的单元格并按 CTRL+K 然后选择选项/选项卡“放置在此文档中”并选择要激活的选项卡来执行此操作。如果您单击文本(现在是链接),则配置的工作表将变为活动/选中状态。

