0

I'm trying to match an obtained property from one class with another class's same property at run time. After some research, I found out that there is such thing as "Reflection" in .net but Im using just VBA. Just for background: I'm automating an application using this code, so some objects are exposed, while others are not.

The way I'm currently doing it is using a property of obtained class "Description", and use that to search for the same property at the targeted class.

Set TargetVar = hySetOperations.Item(j).TargetVariable 'This is a RealVariable a property that refers to a class
Set SourceObj =hySetOperations.Item(j).SourceObject  'This is also a RealVariable
'In order to import variable from source object, we r gonna use TargetVariable description and truncate space, and use it (This might not work if description
'is different than actual name of the variable)
Dim RealVarString As String
RealVarString = TargetVar.Description
'Trim spaces
RealVarString = Replace (RealVarString, " ", "")
Set SourceVar = CallByName ( SourceObj, RealVarString, vbGet)

This actually works for most of the cases since "description" is usually the same as property's name, but with spaces. However, in some cases, this is not the case, in which things go south.

kara
  • 3,205
  • 4
  • 20
  • 34
Peter
  • 1
  • Try `Trim` Function instead of `Replace`. That should get rid of all spaces. Could you provide an example of a case where the class and property are different, and different how? – A Cohen Jun 27 '19 at 19:46
  • thank you for your comment. well, `Set TargetVar = hySetOperations.Item(j).TargetVariable ` for an example TragetVariable is a property of the class container "hySetOperations" but it will return a class and assign it to TargetVar, from which, later I can obtain methods inside it such as `TargetVar.Description` – Peter Jun 28 '19 at 11:23
  • Are you aware of [Microsoft Visual Basic For Applications Extensibility](http://www.cpearson.com/excel/vbe.aspx)? – Daniel Dušek Jun 29 '19 at 20:00
  • One example [here](https://stackoverflow.com/questions/27711077/loop-though-all-udf-names-in-project/27712546#27712546). – Daniel Dušek Jun 29 '19 at 20:04

0 Answers0