vba Excel Shapes.Range(Array("someName")) - 定义的范围是多少?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28587485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel Shapes.Range(Array("someName")) - whats the defined range?
提问by derMax
I have the following code snippet in Excel VBA:
我在 Excel VBA 中有以下代码片段:
With Worksheets("MLS").Shapes.Range(Array("Rounded Rectangle 1")).Fill
.ForeColor.RGB = RGB(166, 166, 166)
.Transparency = 0.3
End With
I don't know where "Rounded Rectangle 1" is defined and what kind of shape or range it refers to. It is not defined within the VBA Code, I have already tried searching the whole project for the name.
我不知道“圆角矩形 1”在哪里定义以及它指的是哪种形状或范围。它没有在 VBA 代码中定义,我已经尝试在整个项目中搜索名称。
Where can I find the definition of "Rounded Rectangle 1" and what might have been the programmers intent in referring to a range/shape using this shapes/range/array construct?
我在哪里可以找到“圆角矩形 1”的定义,以及程序员使用这个形状/范围/数组构造来引用范围/形状的意图是什么?
采纳答案by Aiken
Worksheets("MLS").Shapes.Range(Array("Rounded Rectangle 1"))
refers to a shape named "Rounded Rectangle 1" on the worksheet "MLS" so you won't find the definition you're looking for in your code, it's an object that exists on the worksheet.
Worksheets("MLS").Shapes.Range(Array("Rounded Rectangle 1"))
指的是工作表“MLS”上名为“圆角矩形 1”的形状,因此您不会在代码中找到您要查找的定义,它是工作表上存在的对象。
Worksheets("SheetName").Shapes.Range([arg])
is used to reference a subset of the shapes present on the named worksheet (i.e. objects in that sheet's Shapes
collection). The argument of the Shapes.Range
method can either be:
Worksheets("SheetName").Shapes.Range([arg])
用于引用命名工作表上存在的形状子集(即该工作表Shapes
集合中的对象)。该Shapes.Range
方法的参数可以是:
- An Integer, referring to the index of the shape in the
Shapes
collection - A String, referring to the name of a shape in the
Shapes
collection. - An Array containing strings and/or integers, referring to the names/indices of shapes in the
Shapes
collection.
- 一个整数,指的是
Shapes
集合中形状的索引 - 一个字符串,指的是
Shapes
集合中形状的名称。 - 包含字符串和/或整数的数组,指的是
Shapes
集合中形状的名称/索引。
In your specific case the use of Array("Rounded Rectangle 1")
is unnecessary and the line in question could have been written as
在您的具体情况下,使用Array("Rounded Rectangle 1")
是不必要的,有问题的行可以写成
Worksheets("MLS").Shapes.Range("Rounded Rectangle 1")
with the same effect, or even just
具有相同的效果,甚至只是
Worksheets("MLS").Shapes("Rounded Rectangle 1")
However if there were multiple Rounded Rectangles on your sheet then you would need to use the full fat reference your mystery programmer used, something along the lines of
但是,如果您的工作表上有多个圆角矩形,那么您将需要使用神秘程序员使用的完整引用,类似于
Worksheets("MLS").Shapes.Range(Array("Rounded Rectangle 1", "Rounded Rectangle 2", "Rounded Rectangle 3"))
Which would return a collection containing the shape objects Rounded Rectangle 1, 2 & 3.
这将返回一个包含圆角矩形 1、2 和 3 形状对象的集合。
回答by Portland Runner
When you create a shape Excel will automatically name it for you. You can change this name by selecting the shape and changing it in the Name Box.
创建形状时,Excel 会自动为您命名。您可以通过选择形状并在名称框中更改它来更改此名称。
As @Rory pointed out, if your code is working then the shape is located on the MLS sheet.
正如@Rory 指出的那样,如果您的代码正在运行,则该形状位于 MLS 表上。