Identifying Userform Control Type
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 |
Identifying Userform Control Type
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 Nigel RS wrote: 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 |
Identifying Userform Control Type
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 "Nigel RS" wrote in message ... 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 |
Identifying Userform Control Type
Hi
ctl.typeof - does not work but TypeName(ctl) does. Thanks for the pointer "WhytheQ" wrote: 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 Nigel RS wrote: 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 |
Identifying Userform Control Type
Thank You
I used TypeName(ctr) as the assignment value Cheers "Peter T" wrote: 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 "Nigel RS" wrote in message ... 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 |
All times are GMT +1. The time now is 09:40 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com