将变量设置为Property vba

时间:2019-09-14 15:36:08

标签: vba

您好,我正在尝试弄清楚如何将变量定义为属性,我将编写一些代码来显示我的意思。

谢谢

'i want to call the Selection.ShapeRange.Width

Set img = Selection.ShapeRange ' -- Looks Ok here
img.width = 200 ' -- Works good 

set largo = img.width

largo = 200  ' Here the selected image should be enlarged to 200px Crash :(

1 个答案:

答案 0 :(得分:0)

当您拥有two values you want to swap(此处是Height的{​​{1}}和Width属性值)时,您只需要一个变量来保存值之一: / p>

Shape

然后,您可以从暂时存储在局部变量中的属性开始进行交换:

Dim originalHeight As Double
originalHeight = img.Height