I am trying to make an app that opens a user form at the start, while Excel is being hidden.
The idea is: you open the file, you see the user form without having to see Excel.
When I try to hide the workbook with VBA, it opens empty grey windows. I can only close these windows in Task Manager.
Why does this happen and how can I fix it?
I tried this code in the ThisWorkbook module in the VBA editor:
Private Sub Workbook_Activate()
Application.Visible = False
UserForm1.Show
End Sub
It hides the main Excel screen, but shows grey windows.
Instead of ThisWorkbook I put this code in a module:
Sub Auto_open()
UserForm1.Show
End Sub
It also opens the grey windows.
I think the answer is not to try to hide the app, but to move it out of view. Try this code:
Option Explicit
Private myWindow As Window
Public Sub showForm()
UserForm1.Show
Set myWindow = Application.Windows(1)
myWindow.WindowState = xlNormal
'// move the window out of view here
myWindow.Top = -1000
UserForm1.Top = 50
UserForm1.Left = 50
End Sub
Public Sub hideForm()
myWindow.Top = 100
myWindow.WindowState = xlNormal
Unload UserForm1
End Sub