Creating a list of all controls on all forms

HighAndWilder

Well-known Member
Joined
Nov 4, 2006
Messages
660
Office Version
  1. 365
Platform
  1. Windows
Hi

Whilst I am quite familiar with creating a list of controls and properties for a form by using code in the forms
code module I cannot find a way of doing this for all forms.

If I correct in thinking that the userforms collection only includes loaded forms do I have to load all
forms and loop through the controls in each one in turn?

A pointer in the right direction would be appreciated.

Thanks
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi.

Thanks for your reply but that link seems to link to an Access topic. Do you know of a similar Excel one.

HignAndWilder
 
Upvote 0
.
Code:
Option Explicit


Sub ListControls()
    Dim lCntr As Long
    Dim aCtrls() As Variant
    Dim ctlLoop As MSForms.Control


     'Change UserForm Name In The Next Line
    For Each ctlLoop In UserForm1.Controls
        lCntr = lCntr + 1: ReDim Preserve aCtrls(1 To lCntr)
        'Gets Type and name of Control
        aCtrls(lCntr) = TypeName(ctlLoop) & ":" & ctlLoop.Name
    Next ctlLoop
     'Change Worksheet Name In The Next Line
    Worksheets("Sheet1").Range("A1").Resize(UBound(aCtrls)).Value = Application.Transpose(aCtrls)
End Sub
 
Upvote 0
Here's some very simple, totally without error handling, code that will list all the controls in all the userforms in the active workbook.
Code:
Sub ListForms()
Dim vbproj As Object
Dim vbcomp As Object

    Set vbproj = ActiveWorkbook.VBProject
    
    For Each vbcomp In vbproj.vbcomponents
        If vbcomp.Type = 3 Then
               ListControls vbcomp
        End If
    Next vbcomp
End Sub

Sub ListControls(vbformcomp As Object)
Dim ctl As Object
    
    Debug.Print vbformcomp.Name
    
    For Each ctl In vbformcomp.designer.Controls
        Debug.Print vbTab & ctl.Name & vbTab & TypeName(ctl)
    Next ctl
    
End Sub
 
Upvote 0
Thanks Norie

That is just what I was after.

I now need to loop through all the properties of each control but after trying to work out the syntax I am stuck again.

I will post another question.

HighAndWild
 
Upvote 0

Forum statistics

Threads
1,223,871
Messages
6,175,099
Members
452,612
Latest member
MESTeacher

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