特定工作簿不可见 Excel VBA
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41058326/
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
Specific workbook invisible Excel VBA
提问by franciscofcosta
I am writing a script in Excel VBA where the Workbook
is supposed to open with a UserForm
. I want only the UserForm
to be visible and the excel window itself to be invisible. As such, I have written the following code for the opening of the Workbook
:
我正在 Excel VBA 中编写一个脚本,其中Workbook
应该以UserForm
. 我只希望UserForm
是可见的,而 excel 窗口本身是不可见的。因此,我编写了以下用于打开 的代码Workbook
:
Private Sub Workbook_Open()
'Application launch
Application.Visible = False 'Hide Excel window
EnableResize = False
Application.DisplayFullScreen = True 'Preset fullscreeen mode
Application.CommandBars("Full Screen").Enabled = False 'Hide command bars
WelcomeForm.Show 'Show welcome UserForm
End Sub
I realize that I have set the whole Excel application to be invisible. In this sense, what happens now is that when I have other Excel workbooks open, they turn invisible as soon as I open this one. How could I make it so that this setting only applies to this specific workbook? Thank you
我意识到我已将整个 Excel 应用程序设置为不可见。从这个意义上说,现在发生的情况是,当我打开其他 Excel 工作簿时,一旦我打开这个工作簿,它们就会变得不可见。我如何才能使此设置仅适用于此特定工作簿?谢谢
回答by arcadeprecinct
Partial answer:You can set the window property .Visible
as well
部分答案:可以设置窗口属性.Visible
以及
ThisWorkbook.Windows(1).Visible = False
however this won't hide the application (there will be an empty Excel window if you only have one workbook open) so you need to check for that first
但是,这不会隐藏应用程序(如果您只打开一个工作簿,则会有一个空的 Excel 窗口),因此您需要先检查一下
If Application.Workbooks.Count > 1 Then
ThisWorkbook.Windows(1).Visible = False
Else
Application.Visible = False
End If
回答by Solar Mike
There is a choice to be made here:
这里有一个选择:
Sub HideSheet()
Dim sheet As Worksheet
Set sheet = ActiveSheet
' Hides the sheet but users will be able to unhide it using the Excel UI
sheet.Visible = xlSheetHidden
' Hides the sheet so that it can only be made visible using VBA
sheet.Visible = xlSheetVeryHidden
End Sub
More detail in this SO question
这个SO问题中的更多细节