Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I have a userform in excel vba.
What I wanted was to hide the excel book when the form opens. But that used to close all other open excel books as well.

I would like to close only the particular excel that has the form associated with it.

Any help or hint will be of great help.

What I have tried:

VB
Application.Visible=False

This line closes all other open excel workbooks. And making it true keeps open the excel for userform.

And this does not work
ThisWorkbook.ActiveSheet.Visible = False
Posted
Updated 14-Aug-17 6:57am
Comments
RedDk 12-Aug-17 22:33pm    
see here:

https://www.codeproject.com/Questions/1180939/Vba-userform-unhide-excel-application
planetz 13-Aug-17 8:52am    
that closes all other excel files.

planetz[^] wrote:
I would like to close only the particular excel that has the form associated with it.


In a short: You can't! As long as associated workbook is a parent of UserForm, you can't close that workbook (which is embedded in it).

You can only imitate the hide of window associated with workbook, by minimizing it.
 
Share this answer
 
Actually, you CAN! If you're OK with it starting hidden.

Save the workbook as a macro enabled add-in (.xlam)
and use the workbook open event to load up your user form

If you intend to eventually show the workbook, then this may not be workable.

VB
Private Sub Workbook_Open()
    
    Load UFTest
    UFTest.Show
    
End Sub


And your macro code may need to be modified to make sure that you're referencing the workbook/worksheet/range that you intend.

This may prove to be more hassle than it's worth, but give it a shot!

OR, you could use your PERSONAL.xlsb workbook to house the user form. This is generally not visible when you start excel, but the code and forms are useable.

I guess that it all depends on what your user form will be doing and what workbooks it might need to interact with, or whether you'll be distributing the workbook for others to use.... (not advisable with the PERSONAL workbook.)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900