excel - 有没有办法在 VBA 运行时匹配类属性?
问题描述
我试图在运行时将从一个类中获得的属性与另一类的相同属性进行匹配。经过一番研究,我发现.net中有“反射”之类的东西,但我只使用VBA。仅作为背景:我正在使用此代码自动化应用程序,因此有些对象是公开的,而其他对象则没有。
我目前这样做的方式是使用获得的类“描述”的属性,并使用它在目标类中搜索相同的属性。
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)
这实际上适用于大多数情况,因为“描述”通常与属性名称相同,但带有空格。但是,在某些情况下,情况并非如此,事情会向南发展。
解决方案
推荐阅读
- linux - armitage teamserver 在启动 ubuntu 时抛出连接被拒绝
- gradle - 如何在 Gradle 构建中自动运行 google-java-format?
- php - 密码加密过时
- python-3.x - Beautifullsoup 获取标签中的文本
- typescript - 如何在 Typescript 中保留可变长度元组的类型信息?
- javascript - 如何在页面加载时替换多个标签中的单词实例?
- python - 列表复制与引用 - 2D 矩阵旋转
- html - 通过Angular获取css样式的像素值
- java - 我的布尔变量无法解析为我的 while 语句中的变量
- nginx - NGINX 使用查询参数重写到文件