Identifying Userform Control Type

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All
How can I identifiy the type of control (command button, testbox etc.) on a
userform?

I wish to do two things...

1. Store the control type in a sheet cell
2. Use a conditional depending on the control type

Thanks
 
Hi Nigel.
Something like the following code, when used in the code window behind
the userform, seems to work:

'=============================
Dim ctl As Control
dim i as integer

i=1

For Each ctl In Me.Controls

Activesheet.cells(i,1) = ctl.typeof 'this will list the type in
column1

if ctl.TypeOf ctl Is MSForms.textbox then
msgbox "Your textbox contains the following text " & ctl.text
end if

i=i+1

next ctl
'=============================

Hope this is a start for you
Rgds
J
 
dim ctr as control
for each ctr in myform.controls
n = n + 1
sType = typename(ctr)
cells(n,1) = sType
cells(n,2) = ctr.name

select case sType
case "CommandButton": 'code
' etc
end select
next

(not tested)

Regards,
Peter T
 
Hi

ctl.typeof - does not work but

TypeName(ctl) does.

Thanks for the pointer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top