ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   is there an Eval() in Excel VBA (https://www.excelbanter.com/excel-programming/389154-there-eval-excel-vba.html)

clara

is there an Eval() in Excel VBA
 
Hi all,

I am going to handle a group of controls which are in
"txtControl1","txtControl2",
"txtControl3",... format. So, It is likely to use a loop in which the
"txtControl" part is concacted with the number part like "txtControl"&i, so I
like to use a Eval function to converse the string "txtControl"& i into
control. How can I do it?


CLara
--
thank you so much for your help

MDW

is there an Eval() in Excel VBA
 
I'm not sure I entirely understand what you're trying to do, but this code
might be a start. It allows you to set an object reference to a control based
on the name.

Note that I dimensioned the controls with the generic term "Control" instead
of specifying "TextBox" or whatever they might be. Once you've got the
reference to the control, you can still access all the properties and methods
for that control even if they don't show up on the auto list members view.

Dim I As Integer
Dim C As Control, objMyControl As Control

I = 2 ' You can supply the value of I any way you want, from a parameter, etc.

For Each C In Me.Controls

If C.Name = "txtControl" & I Then

Set objMyControl = C
Exit For

End If


Next

' Do stuff with your control objMyControl


Set objMyControl = Nothing

--
Hmm...they have the Internet on COMPUTERS now!


"clara" wrote:

Hi all,

I am going to handle a group of controls which are in
"txtControl1","txtControl2",
"txtControl3",... format. So, It is likely to use a loop in which the
"txtControl" part is concacted with the number part like "txtControl"&i, so I
like to use a Eval function to converse the string "txtControl"& i into
control. How can I do it?


CLara
--
thank you so much for your help


clara

is there an Eval() in Excel VBA
 
HI MDW,

How can you converse the generic control variable c into a its original
format such textbox

Clara
--
thank you so much for your help


"MDW" wrote:

I'm not sure I entirely understand what you're trying to do, but this code
might be a start. It allows you to set an object reference to a control based
on the name.

Note that I dimensioned the controls with the generic term "Control" instead
of specifying "TextBox" or whatever they might be. Once you've got the
reference to the control, you can still access all the properties and methods
for that control even if they don't show up on the auto list members view.

Dim I As Integer
Dim C As Control, objMyControl As Control

I = 2 ' You can supply the value of I any way you want, from a parameter, etc.

For Each C In Me.Controls

If C.Name = "txtControl" & I Then

Set objMyControl = C
Exit For

End If


Next

' Do stuff with your control objMyControl


Set objMyControl = Nothing

--
Hmm...they have the Internet on COMPUTERS now!


"clara" wrote:

Hi all,

I am going to handle a group of controls which are in
"txtControl1","txtControl2",
"txtControl3",... format. So, It is likely to use a loop in which the
"txtControl" part is concacted with the number part like "txtControl"&i, so I
like to use a Eval function to converse the string "txtControl"& i into
control. How can I do it?


CLara
--
thank you so much for your help


Tim

is there an Eval() in Excel VBA
 
Form controls or Control Toolbox controls ?
On a form or an a worksheet?

Tim


"clara" wrote in message
...
Hi all,

I am going to handle a group of controls which are in
"txtControl1","txtControl2",
"txtControl3",... format. So, It is likely to use a loop in which the
"txtControl" part is concacted with the number part like "txtControl"&i,
so I
like to use a Eval function to converse the string "txtControl"& i into
control. How can I do it?


CLara
--
thank you so much for your help




Jon Peltier

is there an Eval() in Excel VBA
 
Try Typename(C)

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"clara" wrote in message
...
HI MDW,

How can you converse the generic control variable c into a its original
format such textbox

Clara
--
thank you so much for your help


"MDW" wrote:

I'm not sure I entirely understand what you're trying to do, but this
code
might be a start. It allows you to set an object reference to a control
based
on the name.

Note that I dimensioned the controls with the generic term "Control"
instead
of specifying "TextBox" or whatever they might be. Once you've got the
reference to the control, you can still access all the properties and
methods
for that control even if they don't show up on the auto list members
view.

Dim I As Integer
Dim C As Control, objMyControl As Control

I = 2 ' You can supply the value of I any way you want, from a parameter,
etc.

For Each C In Me.Controls

If C.Name = "txtControl" & I Then

Set objMyControl = C
Exit For

End If


Next

' Do stuff with your control objMyControl


Set objMyControl = Nothing

--
Hmm...they have the Internet on COMPUTERS now!


"clara" wrote:

Hi all,

I am going to handle a group of controls which are in
"txtControl1","txtControl2",
"txtControl3",... format. So, It is likely to use a loop in which the
"txtControl" part is concacted with the number part like
"txtControl"&i, so I
like to use a Eval function to converse the string "txtControl"& i into
control. How can I do it?


CLara
--
thank you so much for your help




clara

is there an Eval() in Excel VBA
 
Hi Tim,

They are form controls
--
thank you so much for your help


"Tim" wrote:

Form controls or Control Toolbox controls ?
On a form or an a worksheet?

Tim


"clara" wrote in message
...
Hi all,

I am going to handle a group of controls which are in
"txtControl1","txtControl2",
"txtControl3",... format. So, It is likely to use a loop in which the
"txtControl" part is concacted with the number part like "txtControl"&i,
so I
like to use a Eval function to converse the string "txtControl"& i into
control. How can I do it?


CLara
--
thank you so much for your help






All times are GMT +1. The time now is 05:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com