Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Listing Userform Names

Hi All
I am trying to list all userform controls. Part of this process requires
that I also show the userform name and caption.
In testing I discover an anomoly, that I cannot resolve - the first test
below works and correctly prints the userform name and caption. the second
does not work - can someone explain why please?

' this works
Debug.Print ufReport.Name, ufReport.Caption

' this does not work?
Dim uf As UserForm
Load ufReport
For Each uf In UserForms
Debug.Print uf.Name, uf.Caption
Next
Unload ufReport




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default Listing Userform Names

I know you are looking for an explanation to your question. I do not have
that. However, you could iterate through the forms like this(if they are
already loaded)

For i = 1 To UserForms.Count
Debug.Print UserForms(i - 1).Name
Next i


"Nigel RS" wrote:

Hi All
I am trying to list all userform controls. Part of this process requires
that I also show the userform name and caption.
In testing I discover an anomoly, that I cannot resolve - the first test
below works and correctly prints the userform name and caption. the second
does not work - can someone explain why please?

' this works
Debug.Print ufReport.Name, ufReport.Caption

' this does not work?
Dim uf As UserForm
Load ufReport
For Each uf In UserForms
Debug.Print uf.Name, uf.Caption
Next
Unload ufReport




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default Listing Userform Names

While I do not have an answer to your good question as I too have wondered
about that.. here is another way of iterating through the loaded collection
of forms

For i = 1 To UserForms.Count
Debug.Print UserForms(i - 1).Name
Next i


"Nigel RS" wrote:

Hi All
I am trying to list all userform controls. Part of this process requires
that I also show the userform name and caption.
In testing I discover an anomoly, that I cannot resolve - the first test
below works and correctly prints the userform name and caption. the second
does not work - can someone explain why please?

' this works
Debug.Print ufReport.Name, ufReport.Caption

' this does not work?
Dim uf As UserForm
Load ufReport
For Each uf In UserForms
Debug.Print uf.Name, uf.Caption
Next
Unload ufReport




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Listing Userform Names

That is because a user form does not exist in the userforms collection until
after it has been loaded.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Nigel RS" wrote in message
...
Hi All
I am trying to list all userform controls. Part of this process requires
that I also show the userform name and caption.
In testing I discover an anomoly, that I cannot resolve - the first test
below works and correctly prints the userform name and caption. the second
does not work - can someone explain why please?

' this works
Debug.Print ufReport.Name, ufReport.Caption

' this does not work?
Dim uf As UserForm
Load ufReport
For Each uf In UserForms
Debug.Print uf.Name, uf.Caption
Next
Unload ufReport






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Listing Userform Names

This will return nothing in most instances, unless the userforms have been
loaded.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Alok" wrote in message
...
I know you are looking for an explanation to your question. I do not have
that. However, you could iterate through the forms like this(if they are
already loaded)

For i = 1 To UserForms.Count
Debug.Print UserForms(i - 1).Name
Next i


"Nigel RS" wrote:

Hi All
I am trying to list all userform controls. Part of this process requires
that I also show the userform name and caption.
In testing I discover an anomoly, that I cannot resolve - the first test
below works and correctly prints the userform name and caption. the

second
does not work - can someone explain why please?

' this works
Debug.Print ufReport.Name, ufReport.Caption

' this does not work?
Dim uf As UserForm
Load ufReport
For Each uf In UserForms
Debug.Print uf.Name, uf.Caption
Next
Unload ufReport








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default Listing Userform Names

Sorry for the similar two responses already to your question. The first time
I got an error and thought the response did not go through.

Here is anothe way that I found one can iterate

Dim uf As Object
For Each uf In UserForms
Debug.Print uf.Caption
Next uf

This is taken from Chip Pearson's explanation.
http://groups.google.com/group/micro...3e7c01 a6ff7f

"Nigel RS" wrote:

Hi All
I am trying to list all userform controls. Part of this process requires
that I also show the userform name and caption.
In testing I discover an anomoly, that I cannot resolve - the first test
below works and correctly prints the userform name and caption. the second
does not work - can someone explain why please?

' this works
Debug.Print ufReport.Name, ufReport.Caption

' this does not work?
Dim uf As UserForm
Load ufReport
For Each uf In UserForms
Debug.Print uf.Name, uf.Caption
Next
Unload ufReport




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 318
Default Listing Userform Names

Bob,
I did say that.?

"Bob Phillips" wrote:

This will return nothing in most instances, unless the userforms have been
loaded.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Alok" wrote in message
...
I know you are looking for an explanation to your question. I do not have
that. However, you could iterate through the forms like this(if they are
already loaded)

For i = 1 To UserForms.Count
Debug.Print UserForms(i - 1).Name
Next i


"Nigel RS" wrote:

Hi All
I am trying to list all userform controls. Part of this process requires
that I also show the userform name and caption.
In testing I discover an anomoly, that I cannot resolve - the first test
below works and correctly prints the userform name and caption. the

second
does not work - can someone explain why please?

' this works
Debug.Print ufReport.Name, ufReport.Caption

' this does not work?
Dim uf As UserForm
Load ufReport
For Each uf In UserForms
Debug.Print uf.Name, uf.Caption
Next
Unload ufReport







  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Listing Userform Names

Sub test()
Dim oVBP As Object ' VBProject
Dim oCmp As Object ' VBComponent
Dim ctl As Control

For Each oCmp In ThisWorkbook.VBProject.VBComponents
If oCmp.Type = 3& Then ' userform module
Debug.Print oCmp.Name
For Each ctl In oCmp.designer.Controls
Debug.Print , ctl.Name
Next
End If
Next

End Sub

You would need Trust access to VBProjects but not necessary to load the
forms

Regards,
Peter T

"Nigel RS" wrote in message
...
Hi All
I am trying to list all userform controls. Part of this process requires
that I also show the userform name and caption.
In testing I discover an anomoly, that I cannot resolve - the first test
below works and correctly prints the userform name and caption. the second
does not work - can someone explain why please?

' this works
Debug.Print ufReport.Name, ufReport.Caption

' this does not work?
Dim uf As UserForm
Load ufReport
For Each uf In UserForms
Debug.Print uf.Name, uf.Caption
Next
Unload ufReport






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Listing Userform Names

I see. Nut do not understand why?

If I define uf as a userform my code fails, if I define it as an object and
then declare it in the loop by assigning each userform it does!!

Not very intuitive, but then you live and learn

Many thanks for the feedback

--
Cheers
Nigel



"Alok" wrote in message
...
Sorry for the similar two responses already to your question. The first
time
I got an error and thought the response did not go through.

Here is anothe way that I found one can iterate

Dim uf As Object
For Each uf In UserForms
Debug.Print uf.Caption
Next uf

This is taken from Chip Pearson's explanation.
http://groups.google.com/group/micro...3e7c01 a6ff7f

"Nigel RS" wrote:

Hi All
I am trying to list all userform controls. Part of this process requires
that I also show the userform name and caption.
In testing I discover an anomoly, that I cannot resolve - the first test
below works and correctly prints the userform name and caption. the
second
does not work - can someone explain why please?

' this works
Debug.Print ufReport.Name, ufReport.Caption

' this does not work?
Dim uf As UserForm
Load ufReport
For Each uf In UserForms
Debug.Print uf.Name, uf.Caption
Next
Unload ufReport






  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Listing Userform Names

Neat way of avoiding the loading issue. thanks

--
Cheers
Nigel



"Peter T" <peter_t@discussions wrote in message
...
Sub test()
Dim oVBP As Object ' VBProject
Dim oCmp As Object ' VBComponent
Dim ctl As Control

For Each oCmp In ThisWorkbook.VBProject.VBComponents
If oCmp.Type = 3& Then ' userform module
Debug.Print oCmp.Name
For Each ctl In oCmp.designer.Controls
Debug.Print , ctl.Name
Next
End If
Next

End Sub

You would need Trust access to VBProjects but not necessary to load the
forms

Regards,
Peter T

"Nigel RS" wrote in message
...
Hi All
I am trying to list all userform controls. Part of this process requires
that I also show the userform name and caption.
In testing I discover an anomoly, that I cannot resolve - the first test
below works and correctly prints the userform name and caption. the
second
does not work - can someone explain why please?

' this works
Debug.Print ufReport.Name, ufReport.Caption

' this does not work?
Dim uf As UserForm
Load ufReport
For Each uf In UserForms
Debug.Print uf.Name, uf.Caption
Next
Unload ufReport








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
Listing names and id and corresponding software NeedExcelHelp07 Excel Worksheet Functions 3 May 31st 07 06:58 PM
Userform listing Nigel RS[_2_] Excel Programming 7 October 11th 06 09:25 AM
Listing all userform controls Nigel RS[_2_] Excel Programming 0 October 10th 06 02:13 PM
Listing the names of your worksheets gunslinger Excel Discussion (Misc queries) 3 May 30th 06 11:12 PM
Listing of Sheet names Will Fleenor Excel Worksheet Functions 1 November 17th 04 05:19 PM


All times are GMT +1. The time now is 04:11 PM.

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"