ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Property question (https://www.excelbanter.com/excel-programming/273586-property-question.html)

Eric Bentzen

Property question
 
Hi.

Is it possible to reference a property name using a variable?

Let's say I have a class module, clMyClass, with a string property named
"sMystring".

Now I would like to do something along this line:

Sub Example()
Dim sText as string
Dim vVar

sText = "Text to put in the property sMystring"
vVar = sMystring 'Actually I find the property name elsewhere
clMyClass.vVar = sText

End Sub

But this fails. I cannot make it work either if I use an object instead of a
variant. Any suggestions?

Regards Eric Bentzen




Chip Pearson

Property question
 
Eric,

In Excel 2000 and later, you can use the CallByName function to do
this. E.g.,


Dim PropName As String
PropName = "Value"
CallByName clMyClass, PropName, vbLet, sText

See help for CallByName for more details.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Eric Bentzen" wrote in message
...
Hi.

Is it possible to reference a property name using a variable?

Let's say I have a class module, clMyClass, with a string

property named
"sMystring".

Now I would like to do something along this line:

Sub Example()
Dim sText as string
Dim vVar

sText = "Text to put in the property sMystring"
vVar = sMystring 'Actually I find the property name elsewhere
clMyClass.vVar = sText

End Sub

But this fails. I cannot make it work either if I use an object

instead of a
variant. Any suggestions?

Regards Eric Bentzen







All times are GMT +1. The time now is 02:38 PM.

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