Page.Layers 属性 (Visio)

返回 对象的 Layers 集合。 此为只读属性。

语法

表达式

表达 一个代表 Page 对象的变量。

返回值

Layers

示例

以下 Microsoft Visual Basic for Applications (VBA) 宏显示如何使用 Layers 属性向图层添加形状。 该宏还使用 Layer 属性获取对特定图层的引用,使用 LayerCount 属性确定形状被分配到的图层的数目,使用 Name 属性获取当前图层的名称。

 
Public Sub Layers_Example() 
 
 Dim vsoPage As Visio.Page 
 Dim vsoShape As Visio.Shape 
 Dim vsoLayer As Visio.Layer 
 Dim vsoLayers As Visio.Layers 
 
 If ActiveDocument Is Nothing Then 
 Documents.Add ("") 
 End If 
 
 Set vsoPage = ActivePage 
 If vsoPage Is Nothing Then 
 Set vsoPage = ActiveDocument.Pages(1) 
 End If 
 
 'Draw a rectangle. 
 Set vsoShape = vsoPage.DrawRectangle(1, 5, 5, 1) 
 
 'Get the Layers collection. 
 Set vsoLayers = vsoPage.Layers 
 
 'Create a layer named ExampleLayer1 and add the shape to it. 
 Set vsoLayer = vsoLayers.Add("ExampleLayer1") 
 vsoLayer.Add vsoShape, 1 
 
 'Create a layer named ExampleLayer2 and add the shape to it. 
 Set vsoLayer = vsoLayers.Add("ExampleLayer2") 
 vsoLayer.Add vsoShape, 1 
 
 'Verify that the shape has been assigned to 2 layers. 
 Debug.Print "The shape is assigned to " & vsoShape.LayerCount & " layers." 
 
 'Get a reference to the first layer. 
 Set vsoLayer = vsoShape.Layer(1) 
 
 'Verify by using the Name property. 
 Debug.Print "Current layer name is """ & vsoLayer.Name & ".""" 
 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。