使用 VBA 隐藏 Excel 工作表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/853270/
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
Hiding an Excel worksheet with VBA
提问by Tmdean
I have an Excel spreadsheet with three sheets. One of the sheets contains formulas for one of the other sheets.
我有一个包含三张工作表的 Excel 电子表格。其中一张工作表包含其他工作表之一的公式。
Is there a programmatic way to hide the sheet which contains these formulas?
有没有一种编程方式来隐藏包含这些公式的工作表?
回答by Tmdean
To hide from the UI, use Format > Sheet > Hide
要从 UI 中隐藏,请使用“格式”>“工作表”>“隐藏”
To hide programatically, use the Visibleproperty of the Worksheetobject. If you do it programatically, you can set the sheet as "very hidden", which means it cannot be unhidden through the UI.
要以编程方式隐藏,请使用对象的Visible属性Worksheet。如果以编程方式执行此操作,则可以将工作表设置为“非常隐藏”,这意味着无法通过 UI 将其取消隐藏。
ActiveWorkbook.Sheets("Name").Visible = xlSheetVeryHidden
' or xlSheetHidden or xlSheetVisible
You can also set the Visible property through the properties pane for the worksheet in the VBA IDE (ALT+F11).
您还可以通过 VBA IDE 中工作表的属性窗格设置 Visible 属性 ( ALT+F11)。
回答by Dirk Vollmar
You can do this programmatically using a VBA macro. You can make the sheet hiddenor very hidden:
您可以使用 VBA 宏以编程方式执行此操作。您可以将工作表隐藏或非常隐藏:
Sub HideSheet()
Dim sheet As Worksheet
Set sheet = ActiveSheet
' this hides the sheet but users will be able
' to unhide it using the Excel UI
sheet.Visible = xlSheetHidden
' this hides the sheet so that it can only be made visible using VBA
sheet.Visible = xlSheetVeryHidden
End Sub
回答by Charles Wood
回答by Andrew Scagnelli
This can be done in a single line, as long as the worksheet is active:
只要工作表处于活动状态,就可以在一行中完成:
ActiveSheet.Visible = xlSheetHidden
However, you may not want to do this, especially if you use any "select" operations or you use any more ActiveSheet operations.
但是,您可能不想这样做,尤其是在您使用任何“选择”操作或使用更多 ActiveSheet 操作时。
回答by Priya Sharma
I would like to answer your question, as there are various methods - here I'll talk about the code that is widely used.
我想回答你的问题,因为方法有很多种——这里我就说一下被广泛使用的代码。
So, for hiding the sheet:
所以,为了隐藏工作表:
Sub try()
Worksheets("Sheet1").Visible = xlSheetHidden
End Sub
There are other methods also if you want to learn all Methods Click here
如果您想学习所有方法,还有其他方法单击此处

