Using EVALUATE to get Userform Control Property Value.

HighAndWilder

Well-known Member
Joined
Nov 4, 2006
Messages
606
Office Version
  1. 365
Platform
  1. Windows
Hi

I am trying to get the property value of a UserForm Control but using the Control Name and the Property stored
in string variables.

I loop through all Controls on the form and a list of properties for each Control Type and use the last line of code to
assign the property value to the varValue variable. The first six lines of code just support the last line for
demonstration purposes.

Dim strProperty As String
Dim strControlName As String
Dim q As String

q = Chr(34)
strProperty = "Left"
strControlName = "cmdCommandButton"

Evaluate ("varValue = Me.Controls(" & q & strControlName & q & ")." & strProperty)

The value of the property is not assigned to the variable varValue but no error is generated.

Does anybody know what I am doing wrong or can suggest another way to achieve what I want to do.

Thanks

HighAndWild
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
If you have the control (as an Object) and the property (as a string), you can use the CallByName function to get an object's property value

Code:
Dim oneControl as Object
Dim varValue as Variant

Set oneControl = Userform1.Controls("cmdCommandButton")

varValue = CallByName(oneControl, "Left", vbGet)

MsgBox varValue


The Evaluate method is only for strings that would be valid worksheet formulas.
 
Last edited:
Upvote 0
Thanks a lot Mike

All part of the long learning curve.

Another project nearly completed now.

HighAndWilder
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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