PDA

View Full Version : [SOLVED] Show UserForm With Application.Visible = False



Olwa
07-05-2017, 01:41 AM
Hi!
Is it possible to only hide the excel application for a specific workbook or something similar?

Im using this code


Private Sub Workbook_Open()
Application.Visible = False
UserForm4.Show
End Sub

to only show the userform, while excel is hidden for the user. It does however cause problems if the user already opened other excel workbooks. Only idea i got so far is unhiding by using Application.Visible = True as the user clicks an image used to close the userform. Not the best solution though as he can't work with other excel sheets while using my userform.

Any suggestions?

mdmackillop
07-05-2017, 01:53 AM
Private Sub Workbook_Open()
ActiveWindow.WindowState = xlMinimized
Userform4.Show
End Sub

Olwa
07-05-2017, 02:10 AM
Tried it, opens the workbook minized (as it is supposed to do i guess?) but doesnt show the userform. Additionally it crashes in a weird way (not able to click or select anything in excel, only able to exit by using task manager).

mdmackillop
07-05-2017, 03:09 AM
Try opening non-modal (I didn't test opening as modal)

Userform4.Show 0

Olwa
07-05-2017, 03:21 AM
Thank you, but its still not doing the job. Now it opens Excel minimized, the application works, but the userform does not show up.

mdmackillop
07-05-2017, 03:27 AM
Does it work if you run it from the VBE

Olwa
07-05-2017, 04:07 AM
I assume VBE means VB-Explorer/Editor and tried running it out of the above code. Nothing happened.

mdmackillop
07-05-2017, 04:11 AM
Can't think of anything else. Can you post your workbook?

GTO
07-05-2017, 06:01 AM
...It does however cause problems if the user already opened other excel workbooks. Only idea i got so far is unhiding by using Application.Visible = True as the user clicks an image used to close the userform. Not the best solution though as he can't work with other excel sheets while using my userform...

Greetings,

I'm not sure if you are trying to hide the entire app, or just the workbook. If the latter, maybe something along the lines of:

ThisWorkbook Code:


Option Explicit

Private frmUserForm1 As UserForm1

Private Sub Workbook_Open()
Set frmUserForm1 = New UserForm1
ThisWorkbook.IsAddin = True
frmUserForm1.Show vbModeless
End Sub


Userform Code:


Option Explicit


Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
ThisWorkbook.IsAddin = False
End Sub


Hope that helps,

Mark

SamT
07-05-2017, 06:30 AM
I don't think you can hide the Application, since I think that also hides all the App's child processes.

GTO
07-05-2017, 06:48 AM
Hi Sam,

You can show the form vbModeless after hiding the app.

Standard Module:


Option Explicit


Private formUserform1 As UserForm1


Sub HideAppShowForm()

Set formUserform1 = New UserForm1
Application.Visible = False
formUserform1.Show vbModeless

End Sub


Userform Code:


Option Explicit


Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Application.Visible = True
End Sub


Mark

SamT
07-05-2017, 07:34 AM
Thanks Mark, Good to know.
I will now change the thread Title to
Show UserForm With Application.Visible = False

mdmackillop
07-07-2017, 09:46 AM
Hi Olwa
Is this solved?