提示:其它语言是由 Google 机器翻译的。 你可以访问 English 版本。
登录
x
or
x
x
马上登记
x

or

如何锁定或冻结Excel中的工作表选项卡?

假设您有一个包含多个工作表的工作簿,则有一个名为Main-sheet的工作表作为工作簿中的第一个选项卡。 而现在,您想要尝试锁定或冻结此工作表选项卡,以使其始终可见,即使在多个工作表中滚动时也是如此。 实际上,没有直接冻结选项卡的方法,但是,您可以使用解决方法来处理此问题。

使用VBA代码锁定或冻结特定的工作表选项卡


冻结/解冻窗格多个工作表:
Kutools for Excel's 冻结/解冻窗格多个工作表 只需点击一下,即可帮助您冻结或解冻工作簿中的所有工作表。
doc冻结多张工作表1

箭头蓝色右泡 使用VBA代码锁定或冻结特定的工作表选项卡


在Excel中,我们可以应用以下VBA代码,使特定的工作表始终位于当前单击的工作表选项卡之前,以便您在滚动任何其他工作表选项卡时总能看到此工作表。 请做如下操作:

1。 按住 ALT + F11 键,然后打开 Microsoft Visual Basic for Applications窗口.

2。 然后选择 的ThisWorkbook 从左边 项目浏览器 窗格中,双击它打开 模块,然后将以下VBA代码复制并粘贴到空白模块中:

VBA代码:冻结或锁定特定的工作表选项卡

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
'Update 20150306
Application.EnableEvents = False
Application.ScreenUpdating = False
If Application.ActiveSheet.Index <> Application.Sheets("Main-sheet").Index Then
    Application.Sheets("Main-sheet").Move Before:=Application.Sheets(Application.ActiveSheet.Index)
    Application.Sheets("Main-sheet").Activate
    Sh.Activate
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

DOC-冷冻片状制表1

3。 然后保存并关闭此代码,现在,当您单击任何工作表选项卡时,此特定工作表将始终位于所单击工作表选项卡的前端,请参阅截图:

DOC-冷冻片状制表2
-1
DOC-冷冻片状制表3

注意:在上面的代码中,主表格是要冻结的表格名称,您可以将其更改为您的需要。


相关文章:

如何在Excel 2010中冻结窗格?

如何一次将冻结/解冻窗格应用于多个工作表?


Kutools for Excel - 最佳办公生产力工具提高80%的生产力

  • 重用: 快速插入 复杂的公式,图表 以及你以前用过的任何东西; 加密单元格 密码; 创建邮件列表 并发送电子邮件...
  • 超级方程式酒吧 (轻松编辑多行文字和公式); 阅读布局 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 不丢失数据; 分裂细胞含量; 组合重复的行/列...防止重复的细胞; 比较范围...
  • 选择复制或唯一 行; 选择空行 (所有细胞都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择......
  • 精确复制 多个单元格而不更改公式参考; 自动创建参考 多张表; 插入项目符号,复选框等等......
  • 提取文本,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级过滤器 (将过滤方案保存并应用到其他工作表); 高级排序 按月/周/日,频率等; 特殊过滤器 用粗体,斜体......
  • 结合工作簿和工作表; 根据键列合并表; 将数据拆分为多个表格; 批量转换xls,xlsx和PDF...
  • 超过300强大的功能。 支持Office / Excel 2007-2019和365。 支持所有语言。 在您的企业或组织中轻松部署。 全功能60天免费试用。
kte tab 201905

Office选项卡为Office提供选项卡式界面,使您的工作更轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,Publisher,Access,Visio和Project。
  • 在同一窗口的新选项卡中打开并创建多个文档,而不是在新窗口中。
  • 通过50%提高您的工作效率,每天为您减少数百次鼠标点击!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Xuan · 1 years ago
    chăng đc gi cả
  • To post as a guest, your comment is unpublished.
    Jesse · 1 years ago
    As Thuyen pointed out 2 years ago, you can't copy data between sheets while this code is active. Furthermore, the code is needlessly complicated. The sheet that you activate is passed to the procedure as the parameter "Sh". This makes the frequent calls to "ActiveSheet" unnecessary, and could cause problems for someone who's trying to modify the code but isn't very experienced.

    Here's my versions that corrects those issues, and even shows how to add a 2nd "Main" sheet (similar to what Dzingai posted):
    -----------------------------------------------------------------

    'These 2 lines aren't necessary if you use the sheets' codenames, which I recommend.
    Set shtMain1 = Worksheets("Main-Sheet-1")
    Set shtMain2 = Worksheets("Main-Sheet-2")

    If Application.CutCopyMode = False Then
    If Sh.Index <> shtMain1.Index And Sh.Index <> shtMain2.Index Then
    shtMain1.Move before:=Sh
    shtMain2.Move before:=Sh
    Sh.Activate
    End If
    End If
  • To post as a guest, your comment is unpublished.
    Sangs · 2 years ago
    This code worked well. Only problem is...if we close the file & open it again it goes off.
    • To post as a guest, your comment is unpublished.
      Dzingai · 2 years ago
      [quote name="Sangs"]This code worked well. Only problem is...if we close the file & open it again it goes off.[/quote]
      Try saving document as Macro-Enabled Workbook. I think it should work well that way.
  • To post as a guest, your comment is unpublished.
    Pablo · 3 years ago
    Is it possible to create one with multiple arguments? Like instead of just moving the one main sheet to the front of where you are working, is it possible to move three tabs in front of what you are working on?
    • To post as a guest, your comment is unpublished.
      dzingai · 2 years ago
      Yes, it is possible, you just have to add more arguments to the if clause using the "AND" like this

      IF Application.ActiveSheet.Index Application.Sheets("Main-sheet").Index AND Application.ActiveSheet.Index Application.Sheets("Other-Main-sheet").Index and so on...
      Then
      Application.Sheets("Main-sheet").Move Before:=Application.Sheets(Application.Sheets("Other-Main-sheet").Index)
      Application.Sheets("Main-sheet").Activate
      Application.Sheets("Other-Main-sheet").Move Before:=Application.Sheets(Application.ActiveSheet.Index)
      Application.Sheets("Other-Main-sheet").Activate
      Sh.Activate
      This will place the Main-Sheet, then the Other-Main-Sheet in front of your active sheet.
  • To post as a guest, your comment is unpublished.
    MEESHA · 3 years ago
    Could not get your code to work, but this one did :)

    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    Dim sc As Long ' count of sheets
    Dim NewPos As Long ' index of serlected sheet

    Application.EnableEvents = False
    Application.ScreenUpdating = False

    If ActiveSheet.Index 1 Then
    sc = Sheets.Count
    NewPos = ActiveSheet.Index
    For i = 2 To NewPos - 1
    Sheets(2).Move After:=Sheets(sc)
    Next i
    Sheets(1).Activate
    Sheets(2).Activate
    End If

    Application.ScreenUpdating = True
    Application.EnableEvents = True
    End Sub
  • To post as a guest, your comment is unpublished.
    Thuyen · 4 years ago
    When I use VBA, I cannot copy data from Main-Sheet to another sheet
    Please help me fix this bug