关闭工作簿时隐藏特定的工作表 [英] Hide specific sheets when closing workbook

查看:52
本文介绍了关闭工作簿时隐藏特定的工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一些VBA代码,该代码应执行以下操作:

I'm creating some VBA code which should do the following:

  1. 需要用户按下按钮a才能输入密码.
  2. 输入正确的密码后,他们便可以访问与团队相关的密码.

他们可以访问的工作表根据他们输入的团队编号和代码而有所不同.因此,当他们输入密码香蕉"时:工作表"Team_1"& Team_1_sub 可见.

The sheets they get access to differs according to the team number and code they enter. So when they enter he password "banana": the sheets "Team_1" & Team_1_sub become visible.

我现在创建了以下代码来实现此目的:

I now created the following code to achieve this:

 Sub filter_tabs()

  Dim answer As String
  answer = InputBox("Please enter your password")

   If answer = "Password" Then
    MsgBox "Correct, je krijgt nu de goede tabs te zien!"
    Worksheets("Team_1").Visible = True
    Worksheets("Team_1_sub").Visible = True

  Else
   MsgBox "Wrong password"
  End If

 End Sub

关于上面的代码的两个问题:

Two questions about the code above:

  1. 当用户关闭文档时,所有工作表应再次消失".有人知道怎么做这个吗?因此,在打开文档表时,"Team_1"和"Team_1_sub"应为标准

  1. When the users close the document all sheet should "disappear" again. Does anybody know how to do this? So when opening the document sheets "Team_1" and "Team_1_sub" should be be standard

Worksheets("Team_1").Visible = False
Worksheets("Team_1_sub").Visible = False

  • 你们能给我一些我是否遵循上述步骤(如果提示用户输入密码然后查看某些选项卡的语句是否不同)是否是实现我的目标的最有效方法呢?最终目标是确保某些团队负责人只能看到某些工作表.

  • Could you guys give me some feedback on whether the procedure I follow above (different if statements where users are prompted for a password and then get to see certain tabs) is the most efficient one to reach my goal? End goal is to make sure certain team leader can only see certain sheets.

    推荐答案

    此处设置了可见的false,您可以使用 Workbook_BeforeClose 方法,如下所示:

    Here for setting visible false, you can use Workbook_BeforeClose method as follow:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    
        Worksheets("Team_1").Visible = False
        Worksheets("Team_1_sub").Visible = False
    
        'must save, if not save, it is not effect.
        Me.Save
    
    End Sub
    

    该方法的引用为一件事是,此方法必须在 ThisWorkBook 模块中.

    One thing is that this method must have in the ThisWorkBook module.

    对于下一个问题,您应该说更多,例如,哪个表用于哪个用户和密码.因为您的代码足以解决您的问题.它可以根据您的要求使用.

    For next question, you should say more like, which sheets for which user and password. Because you code is enough for your question. It can use for your requirement.

    这篇关于关闭工作簿时隐藏特定的工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆