VBA中Shapes集合的使用方法

VBA中Shapes集合的使用方法:可用 Shapes 属性返回 Shapes 集合。下例选定 myDocument 上的所有图形。 VBA, use the Shapes collection: Available Shapes property to return the Shapes collection. The following example is selected on myDocument graphics.Set myDocument = Worksheets(1)myDocument.Shapes.SelectAll 注释:如果要同时对工作表上的所有图形进行某项操作(例如删除或设置属性),请选定所有图形,然后对选定区域应用 ShapeRange 属性以创建一个包含工作表上所有图形的 ShapeRange 对象,然后对 ShapeRange 对象应用适当的属性或方法。 Note: If all graphics in the worksheet for a particular operation (eg, delete, or set properties), select all the graphics, and selected regional applications ShapeRange property to create a worksheet of all graphics ShapeRange object, and then apply the appropriate property or method ShapeRange object. 可用 Shapes(index)(其中 index 是图形的名称或索引号)返回单个的 Shape 对象。下例设置 myDocument 上第一个图形的预设阴影的填充。 Available Shapes (index) (index name or index number of the graph) return a single Shape object. The following example sets on myDocument the default shadow of a graphics fill.Set myDocument = Worksheets(1)myDocument.Shapes(1).Fill.PresetGradient _ msoGradientHorizontal, 1, msoGradientBrass 可用 Shapes.Range(index)(其中 index 是图形的名称或索引号或是它们的一个数组)返回 ShapeRange 集合,该集合代表 Shapes 集合的一个子集。下例设置 myDocument 上的第一个和第三个图形的填充图案。 To available Shapes.Range (index) (where index is the graphic name or index number, or an array) Returns a ShapeRange collection, the collection on behalf of the Shapes collection, a subset of The first and third cases set on myDocument graphics fill pattern.Set myDocument = Worksheets(1)myDocument.Shapes.Range(Array(1, 3)).Fill.Patterned _ msoPatternHorizontalBrick 说明:工作表中的 ActiveX 控件具有两个名称:一个是包含该控件的图形的名称(在查看该工作表时,将显示在“名称”框中),还有一个是该控件的代码名称(“属性”窗口中“(名称)”右边的单元格中)。当首次向工作表中添加控件时,图形名称和代码名称相同。但是,更改其中任何一个名称时,另一个名称并不会自动随之更改。 Description: ActiveX control in the worksheet has two names: one that contains the name of the control graphics (see the worksheet will display the Name box), there is a control code names (“Properties” window “(name)” the right of the cell). When adding controls to the worksheet for the first time, the shape name and code name. However, change a name, another name will not automatically be changed. 在控件事件过程名称中使用的是控件的代码名称,但是,当您从工作表的 Shapes 或 OLEObjects 集合中返回控件时,必须使用图形名称而不是代码名称,只有这样才能通过名称引用控件。例如,假定要向工作表中添加一个复选框,其默认的图形名称和代码名称都是 CheckBox1。如果通过在“属性”窗口的“(名称)”旁边键入“chkFinished”而更改了控件代码名称,则在事件过程名称中必须使用 chkFinished,但是您仍然需要使用 CheckBox1 从 Shapes 或 OLEObject 集合中返回控件,如下例所示。 Used in the control event procedure name is the name of the control code, However, when you return a control from the Shapes or OLEObjects collection of worksheets, you must use the shape name, not a code name, the only way to reference to the control by name. For example, assume that to the table to add a check box, and its default shape name and code names are CheckBox1 to. The type “chkFinished, next to the” Properties “window” (name) “to change the control code name, in the name of the event procedure must be used chkFinished, but you still need to use CheckBox1 set to return control from the Shapes or OLEObject the examples below.Private Sub chkFinished_Click() ActiveSheet.OLEObjects(“CheckBox1”).Object.Value = 1End Sub
友谊之花、爱情之树、以及遗憾之泪!

VBA中Shapes集合的使用方法

相关文章:

你感兴趣的文章:

标签云: