Is it possible to get the (Name) of every control on a form?

lukeshuttlewood

Board Regular
Joined
Jul 27, 2004
Messages
90
Hi

Is it possible, using VBA code to get the (name) of every control on the current user form then deliver that name to a cell on a spreadsheet.

The prgramme would be something like:

* Look at the first control in the userform (If there is some sort of order tag?)
* Get its name
* Put the name in a cell on a spreadsheet
* Look at the next control
* etc etc

Does anyone know any code that can cycle through controls in this manner?

Cheers
Luke
 

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
This seems to work for me:

Code:
Sub test()
Dim ctl As Control, i As Long

i = 1
For Each ctl In UserForm1.Controls
    Cells(i, 1).Value = ctl.Name
    i = i + 1
Next ctl

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,118,081
Messages
5,570,089
Members
412,310
Latest member
mark884
Top