简体   繁体   English

如何使用VBA隐藏工作表?

[英]How do I hide a sheet using VBA?

Microsoft Excel 2010 has Sheet1, Sheet2, Sheet3. Microsoft Excel 2010具有Sheet1,Sheet2,Sheet3。

On Sheet 1, the page is locked. 在工作表1上,页面被锁定。 It contains fields that reference Sheet3. 它包含引用Sheet3的字段。

For example, Sheet1 on A2 is titled "Name" and B2 has =Sheet3!B2. 例如,在A2上的Sheet1标题为“名称”,而B2具有= Sheet3!B2。

On Sheet3, A2 is titled "Name" and B2 is blank unless the user fills it in. Of course Sheet3 Cell B2 auto populates into Sheet1. 在Sheet3上,除非用户填写,否则A2的标题为“名称”,而B2为空白。当然,Sheet3单元格B2自动填充到Sheet1中。

On Sheet 3, I have more similar fields that are editable by users such as address and phone number. 在工作表3上,我有更多类似的字段可供用户编辑,例如地址和电话号码。 However, I would like to hide Sheet3 by creating a button that hides Sheet3 once clicked. 但是,我想通过创建一个单击一次即可隐藏Sheet3的按钮来隐藏Sheet3。 I don't want people that are emailed this file to see this Sheet3 with all the information on it. 我不希望通过电子邮件发送此文件的人看到此Sheet3及其所有信息。 It will confuse automated systems. 它将混淆自动化系统。

I've researched all that I could and found some codes that hides a sheet after information is typed into a certain field but I was not sure how to apply that code to a button. 我已经尽力研究了,发现了一些将信息输入到特定字段后隐藏工作表的代码,但是我不确定如何将该代码应用于按钮。 The purpose for this button is not all my users are tech savvy so this is a quick way to allow them to hide the sheet without the fuss. 此按钮的用途不是我的所有用户都精通技术,因此这是一种允许他们隐藏表格而不必大惊小怪的快速方法。 The button would go on Sheet3 as well. 该按钮也将出现在Sheet3上。

I found a code that could help if someone knows some VBA to convert it to the use of a button. 我发现了一个代码,如果有人知道一些VBA可以将其转换为按钮的使用,该代码将有所帮助。 This code says B6 and B7, hide the sheet. 此代码显示B6和B7,隐藏工作表。 I am really lost how to use button click command with this almost close formula. 我真的迷失了如何在这个几乎封闭的公式中使用按钮单击命令。

Sub ShowHideWorksheets()
Dim Cell As Range
For Each Cell In Range("B6:B7")
ActiveWorkbook.Worksheets(Cell.Value).Visible = Not
ActiveWorkbook.Worksheets(Cell.Value).Visible
Next Cell
End Sub

almost, try: 几乎可以尝试:

ActiveWorkbook.Worksheets(Cell.Value).Visible = xlSheetHidden

or if you want to hide the sheet, and not allow the user to see it in the hidden sheet collection: 或者如果您想隐藏工作表,并且不允许用户在隐藏的工作表集合中看到它:

ActiveWorkbook.Worksheets(Cell.Value).Visible = xlSheetVeryHidden

暂无
暂无

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

相关问题 如何使用VBA在Excel工作表上排列图表? - How do I arrange charts on an excel sheet using VBA? 如何使用VBA从Excel工作表中删除表情符号? - How do I remove emojis from an excel sheet using VBA? 如何在 Excel 中隐藏带有按钮的工作表? - How do I hide a sheet with a button in Excel? 如何在不使用宏或VBA的情况下基于另一个工作表中的单元格值隐藏/取消隐藏工作表 - How to hide/un hide a sheet based on a cell value in another sheet without using macro or vba 如何使用 VBA 代码根据单元格值隐藏 Excel 表 - How to hide Excel Sheet based on cell value using VBA Code 在图表工作表中放置多个图表时,如何使用vba更改图表属性? - When placing multiple charts in a chart sheet, how do I change chart properties using vba? 如何使用 VBA 将遵循特定字符串的动态数据范围从一张纸复制到另一张纸? - How do I copy a dynamic range of data that follows a specific string from one sheet to another using VBA? 如何删除 Excel 表中的一行,该表位于使用 VBA 的用户窗体搜索字段找到的另一张表上? - How do I delete a row in an Excel Table that is on another Sheet that was found with a Userform search field using VBA? 如何使用 VBA 将 excel 表中的信息输入到特定网站的搜索栏? - How do I enter information from my excel sheet to a specific website's search bar using VBA? 如何使用excel VBA将excel选项卡的格式复制并粘贴到除所选工作表以外的其他选项卡上 - How do I copy and paste formatting of excel tab to other tabs except a selected sheet using excel VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM