How to hide a form or make invisible in Excel

dariusd77

New Member
Joined
Jan 24, 2013
Messages
26
How do I make a fomr disappear after another form is opened. basically I have a menu that leads to sub menu(sub form s) so when I click on a button in the menu another form opens but i want the menu form to close. until I open it again by clicking on a button on the other form.

I tried the following but does not work

userform1.visible = false

and userform1.hide....

Neither works

here is the actual code.

Code:
Private Sub btnOpenDatasheetMenu_Click()




frmUsrDataSheet.Show


frmUserFormExample.Visible = False








End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Code:
vbaProject.frmUserFormExample.Hide
vbaProject.frmUsrDataSheet.Show


You might want to consider using one tabbed form. Then you can easily switch between tabs as needed without having to keep track of multiple userforms.
 
Upvote 0
Code:
vbaProject.frmUserFormExample.Hide
vbaProject.frmUsrDataSheet.Show


You might want to consider using one tabbed form. Then you can easily switch between tabs as needed without having to keep track of multiple userforms.


Ok i am very new at this..So I don't know what you mean by ..one tabbed form.. What is that?
 
Upvote 0
Code:
vbaProject.frmUserFormExample.Hide
vbaProject.frmUsrDataSheet.Show


You might want to consider using one tabbed form. Then you can easily switch between tabs as needed without having to keep track of multiple userforms.


Do i have to use "vbaProject" or can i just use frmUserFormExample.Hide...
 
Upvote 0
Hi,
I don't think I have a good explanation. :( It's just the way it is with forms - they just don't have the same scope as other objects in Excel.
 
Upvote 0
I've never had to use vbaProject to do this. This type of code always works for me

Code:
Option Explicit


Private Sub CommandButton1_Click()
    Me.Hide '<- hides this userForm
    UserForm1.Show '<-displays the other UserForm
End Sub

However, one form with a MultiPage control is easier to work with as xenou suggested
 
Upvote 0
You don't need to qualify it with the project name. In fact, since you're referring to the form running the code you should use Me:
Code:
Private Sub btnOpenDatasheetMenu_Click()
Me.Hide
frmUsrDataSheet.Show
Me.Show
End Sub
Assuming your second form is modal (the default), this will hide the first form and load the second form, then whenever the second form is hidden or closed, the first form will be shown again automatically with no code required in the second form to show it. Indeed, you should not use code in the second form to reload the first or you will end up in a circular chain of events.
 
Upvote 0
OK I will try this. I did however use the code by senou and it works. and I did put the code in both the first and second form..just flipping which form tho hide and to show. and it works..but I will try your code since it is more efficient. less code is always better.
 
Upvote 0

Forum statistics

Threads
1,223,734
Messages
6,174,189
Members
452,550
Latest member
southernsquid2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top