简体   繁体   English

如何在Excel中激活特定工作表?

[英]How to activate a specific worksheet in Excel?

I just need to activate a certain worksheet. 我只需要激活某个工作表。 I have a string variable that keeps the name of the worksheet. 我有一个字符串变量,保留工作表的名称。

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. 基本上你想要使用.Activate函数。 Or you can use the .Select function like so: 或者您可以像这样使用.Select函数:

Sub activateSheet(sheetname As String)
'selects sheet of specific name
    Sheets(sheetname).Select
End Sub

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. 它还将改善性能。

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. 您可以通过选择包含文本的单元格并按CTRL + K然后选择选项/选项卡“放置在此文档中”并选择要激活的选项卡来完成此操作。 If you would click the text (that is now a link) the configured sheet will become active/selected. 如果您单击文本(现在是链接),则已配置的工作表将变为活动/已选中。

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

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