Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default Unloading all open and hidden UserForms


I am trying to figure out how to unload all hidden UserForms. I have about
7 UserForms but I use Me.Hide for all of them. At any point when I click the
cancel button on any of the UserForm I want all the open forms that are
hidden to be unloaded.
How do I go about doing this.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Unloading all open and hidden UserForms

You will have to decide which method you want to use to execute the code.
i.e. UserForm_Click event, CommandButton_Click event, etc. but the code
will need to be where it can be initialized while a form is showing,
assuming you are showing them modal.
If you show them modeless, you could use a single command button on a sheet.
If they are modal and you use the form click event, then you would need the
code in each form code module. You can probably figure out the rest.

Private Sub 'your choice of method
For i = UserForms.Count - 1 To 0 Step -1
Unload UserForms(i)
Next
End Sub


"Ayo" wrote in message
...

I am trying to figure out how to unload all hidden UserForms. I have about
7 UserForms but I use Me.Hide for all of them. At any point when I click
the
cancel button on any of the UserForm I want all the open forms that are
hidden to be unloaded.
How do I go about doing this.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Unloading all open and hidden UserForms

Sometimes might want to unload active form last -

' in a normal module
Sub UnloadForms(sName As String)
For i = UserForms.Count - 1 To 0 Step -1
If UserForms(i).Name < sName Then
Unload UserForms(i)
End If
Next

If Len(sName) Then
Unload UserForms(0)
Else
' pass empty string if not called from a form
End If

End Sub


' in userforms
Private Sub CommandButton1_Click()
UnloadForms Me.Name
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then ' little x
UnloadForms Me.Name
End If
End Sub

Regards,
Peter T

"Ayo" wrote in message
...

I am trying to figure out how to unload all hidden UserForms. I have about
7 UserForms but I use Me.Hide for all of them. At any point when I click
the
cancel button on any of the UserForm I want all the open forms that are
hidden to be unloaded.
How do I go about doing this.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Unloading all open and hidden UserForms

Make use of the UserForms collection which will contain all your userforms,
hidden or not.

Try:

Sub UserFormUnload()

For a = 1 To UserForms.Count
Unload UserForms(0)
Next a

End Sub

The collection will re-index itself every time an object is deleted, so we
can repeatedly remove the first item - which has an index of '0'

Helpful? Click Yes.

"Ayo" wrote:


I am trying to figure out how to unload all hidden UserForms. I have about
7 UserForms but I use Me.Hide for all of them. At any point when I click the
cancel button on any of the UserForm I want all the open forms that are
hidden to be unloaded.
How do I go about doing this.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to open a file and a hidden file and hidden toolbar jeremiah Excel Programming 1 October 1st 09 07:58 PM
Unloading /Closing all userforms dunnerca Excel Programming 3 December 31st 07 07:28 PM
Unloading userforms Oggy Excel Programming 6 May 13th 07 11:13 AM
Open Userforms from a Dropdown list skid812pb Excel Discussion (Misc queries) 0 May 23rd 05 11:28 PM
Multiple Userforms open at once RockNRoll[_2_] Excel Programming 1 May 8th 04 11:10 PM


All times are GMT +1. The time now is 03:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"