使用VBA在Excel中选择形状 [英] Selecting a shape in Excel with VBA
问题描述
我正在尝试使用VBA通过名称选择形状.在我的工作表中,我有10个形状,分别为1到10,并想要一个特定的形状.由于某种原因,excel用我的代码选择的形状似乎不是我告诉它选择的名称的形状.据我所知,它选择的形状是随机的.这是我的代码(x值应该检索从1到10输入的数字值):
I am trying to select a shape by name using VBA. In my sheet, I have 10 shapes named 1 to 10 and want a specific one. For some reason, the shape that excel selects with my code does not seem to be the shape with the name I told it to select. As far as I can tell, the shape that it chooses is random. Here is my code (The x value is supposed to retrieve a number value that I input from 1 to 10):
Sub FindTheShape()
Sheets("Fleet 1").Select
Dim x As Long
x = ActiveSheet.Range("$A$1000").End(xlUp).Value
ActiveSheet.Shapes(x).Select
End Sub
请帮助,任何想法都将不胜感激.
Please help, any ideas are greatly appreciated.
推荐答案
当您的形状被命名为1到10时,您的x给出索引号而不是名称,从您的x生成字符串:
Your x gives the index-number not the name, when your shapes are named 1 to 10 make a string from your x:
ActiveSheet.Shapes(CStr(x)).Select
这篇关于使用VBA在Excel中选择形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!