Skip to main content
  1. About
  2. For Teams
Asked
Viewed 16k times
0

I have a userform which is created in vba and I want to display only the userform when I open my excel... is there a way to do this.. I have already tried the codes such as

application.visible = false , activewindow.visible= false

if I use this codes in the module before open the files which are already open will b hidden along with the file which I am opening can someone tel me how can i particularly hide the file which I want to open and display the userform

7
  • Did you try putting application.visible = false in form initialisation event?
    Pankaj Jaju
    –  Pankaj Jaju
    2017-11-16 09:24:03 +00:00
    Commented Nov 16, 2017 at 9:24
  • the problem is if i use application.visible code it hides all the files which are opened in excel .... for example if i m working on a excel data sheet n if i open this userform it hides the datasheet too along with this
    Shahbaz Shaikh
    –  Shahbaz Shaikh
    2017-11-16 10:08:41 +00:00
    Commented Nov 16, 2017 at 10:08
  • Check if the sample code in the answers section works for you.
    Pankaj Jaju
    –  Pankaj Jaju
    2017-11-16 10:44:43 +00:00
    Commented Nov 16, 2017 at 10:44
  • I have already tries this ...it hides the window but the background of excel vl stil be there if I open my file which contains the userform
    Shahbaz Shaikh
    –  Shahbaz Shaikh
    2017-11-16 11:09:26 +00:00
    Commented Nov 16, 2017 at 11:09
  • 1
    Possible duplicate of Excel Useform: How to hide application but have icon in the taskbar
    CommonSense
    –  CommonSense
    2017-11-16 15:12:33 +00:00
    Commented Nov 16, 2017 at 15:12

2 Answers 2

5

Try something like this

1- Create a user form with 2 button (see below pic)

enter image description here

2- ThisWorkbook code

Private Sub Workbook_Open()
    UserForm1.Show vbModeless
End Sub

3- Form code

Private Sub CommandButton1_Click()
    If Workbooks.Count > 1 Then
        Windows("Test.xlsm").Visible = True
    Else
        Application.Visible = True
    End If
End Sub

Private Sub CommandButton2_Click()
    If Workbooks.Count > 1 Then
        Windows("Test.xlsm").Visible = False
    Else
        Application.Visible = False
    End If
End Sub

Private Sub UserForm_Initialize()
    If Workbooks.Count > 1 Then
        Windows("Test.xlsm").Visible = False
    Else
        Application.Visible = False
    End If
End Sub

Private Sub UserForm_Terminate()
    If Workbooks.Count > 1 Then
        Windows("Test.xlsm").Visible = True
    Else
        Application.Visible = True
    End If
End Sub

This will only show or hide the form's workbook. Any other workbooks opened will remain unaffected.

Sign up to request clarification or add additional context in comments.

13 Comments

but if i open only one excel which is having the userform then the background of the excel vl b there ....
@ShahbazShaikh - Updated the code ... basically you have to check the number of workbooks in order to show or hide the entire application or just the workbook.
the bug I found is the other excel file pop ups in background of userform when workbook.count >1
Which is what you want I assumed? You said my first code hides all workbooks and you only wanted to hide the form workbook.
correct in the first code of urs all workbooks wer hiding but the excel template background was visible... in this code if any other excel file is opened it pop ups behind the userform.... how can I see only userform then... u can check the code by parallel opening 2 excel sheets .....
|
0

I think if you ensure that other workbooks are not open, that might solve the problem.

Private Sub Workbook_Open()
 If Workbooks.Count > 1 Then
   MsgBox "Close All excel files before running it"
   ThisWorkbook.Close
 Else
    Application.Visible = False
    frmmain.Show
 End If
End Sub

Comments

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.