![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
|
Is it possible to close a userform when you
go to another worksheet? James |
|
|
|
|
|
#2 |
|
BatCoder
Join Date: Feb 2002
Location: Turkey
Posts: 764
|
In related sheet vba module:
Private Sub Worksheet_Activate() UserForm1.Show vbModeless End Sub Private Sub Worksheet_Deactivate() UserForm1.Hide End Sub |
|
|
|
|
|
#3 |
|
BatCoder
Join Date: Feb 2002
Location: Turkey
Posts: 764
|
the first comment shows userform when you activate Sheet1 and hides when you deactivate it (jump to another one)
This one close the userform completely Private Sub Worksheet_Deactivate() unload UserForm1 End Sub |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
|
I tried the above and get the compile error
"variable not defined" the userform is named menu. any suggestions? James |
|
|
|
|
|
#5 |
|
BatCoder
Join Date: Feb 2002
Location: Turkey
Posts: 764
|
Please use your own Userform name instead UserForm1..
|
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
|
Thank Smozgur,
My error was in "UserForm.Menu" it works and i learned something! James |
|
|
|
|
|
#7 |
|
BatCoder
Join Date: Feb 2002
Location: Turkey
Posts: 764
|
Nice to hear that, about you learned something.
And there are too much to learn, trust me |
|
|
|
|
|
#8 |
|
Board Regular
Join Date: Feb 2002
Location: Huntington Beach, CA USA
Posts: 327
|
Just out of curiosity could it be accomplished without naming a specific
UserForm? |
|
|
|
|
|
#9 |
|
BatCoder
Join Date: Feb 2002
Location: Turkey
Posts: 764
|
You can use
Unload thisworkbook.VBProject.VBComponents(index) But you dont want to do this. Because you have to know exact index of UserForm. You can also check all vbcomponents' types in workbook and when you find the 3 for type for a component then you can understand that it is a userform and unload it. I think using a specific name is easier. But if you have lots of userform and you dont know which is activated then you can apply this kind of code. |
|
|
|
|
|
#10 |
|
BatCoder
Join Date: Feb 2002
Location: Turkey
Posts: 764
|
Hmm, sorry.
Unload thisworkbook.VBProject.VBComponents(index) wont work but it is still possible to set an object instead using it directly and play with it. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|