Specific workbook invisible Excel VBA

时光毁灭记忆、已成空白 提交于 2019-12-12 04:23:07

问题


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:

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


回答1:


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




回答2:


Partial answer: You can set the window property .Visible as well

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

If Application.Workbooks.Count > 1 Then
    ThisWorkbook.Windows(1).Visible = False
Else
    Application.Visible = False
End If


来源:https://stackoverflow.com/questions/41058326/specific-workbook-invisible-excel-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!