Excel VBA Fetch All Control Type And Name From A UserForm

kashif.special2005

Active Member
Joined
Oct 26, 2009
Messages
443
Hi,

I want to create a procedure where I will pass a userform object and that procedure will give me the all controls name and type related to that form, I have created below procedure but it is not working.

When I run procedure "Test2", in the line "Set myForm = FundInfoForm" it is firing the Initialize event of the form, which is I don't want, and in the procedure "PrintAllControlsInAForm" is printing only blank lines.

Please help me resolve this problem or please guide me how can i achieve this task.

Code:
Sub Test2()


    Dim myForm As msforms.UserForm
    
    
    Set myForm = FundInfoForm  [I][B]'Here it is firing the Initialize Event of this form[/B][/I]
    
    Call PrintAllControlsInAForm(myForm)


End Sub




Sub PrintAllControlsInAForm(msfTargetForm As msforms.UserForm)


    Dim msControl As msforms.Control
    
    For Each msControl In msfTargetForm.Controls
    
        Debug.Print mscontrols [I][B]'Here it is printing only blank lines in the Immediate window[/B][/I]
        
    Next msControl


End Sub

Thanks
Kashif
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi,

change this line

Rich (BB code):
Debug.Print mscontrols


to this

Rich (BB code):
Debug.Print msControl.Name

You will note that your original line of code you added "s" to your variable name which is one reason why you got a blank result. You can avoid such errors by adding
Option Explicit to top of your code page where you will be informed at compile time of missing variables.

Dave
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,179
Members
453,021
Latest member
Justyna P

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