0

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

franciscofcosta
  • 833
  • 5
  • 25
  • 53
  • 1
    I don't believe you can. Excel has GLOBAL settings that are independent of the workbook you are looking at. For instance, you can minimize the ribbon while looking at one workbook, then close the workbook and exit, and then run Excel with or without a file. You will see that the ribbon remains minimized. – FDavidov Dec 09 '16 at 10:38
  • 1
    you can also use VeryHidden, see: http://stackoverflow.com/questions/853270/hiding-an-excel-worksheet-with-vba/853327#853327, which stops users easily getting to it. – Solar Mike Dec 09 '16 at 10:46
  • Sometimes the effort involved in making a VBA project in Excel behave like a Windows application is *a lot more* than just investing some time in writing a Windows application. YMMV. – Robin Mackenzie Dec 09 '16 at 11:57

3 Answers3

3

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
arcadeprecinct
  • 3,767
  • 1
  • 12
  • 18
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

Community
  • 1
  • 1
Solar Mike
  • 7,156
  • 4
  • 17
  • 32
0

what you can do is the following

private sub workbook_open ()

userform.activate

end sub

then in the userform code write

Private sub userform_intialize()

application.screenupdate =false

end sub

now you only see the form upon starting

One problem that I do not know how to fix is that you will still see old versions whe you move the window.

Waly
  • 46
  • 5