Layer Property [Visio 2003 SDK Documentation]
Returns the layer to which a shape is assigned.
objRet = object**.Layer**(index)**
objRet A Layer object that represents the requested layer.
object Required. An expression that returns a Shape object.
index Integer. The ordinal of the layer to get.
Version added
4.0
Remarks
If a shape is assigned to three layers, the valid indexes that can be passed to its Layer property are 1 through 3.
To get the number of layers to which a shape is assigned, use the LayerCount property.
Example
This Microsoft Visual Basic for Applications (VBA) macro shows how to use the Layer property to get a reference to a particular layer. It also uses the LayerCount property to determine the number of layers to which a shape is assigned and the Name property to get the name of the current layer.
Public Sub Layer_Example()
Dim vsoPage As Visio.Page
Dim vsoShape As Visio.Shape
Dim vsoLayers As Visio.Layers
Dim vsoLayer As Visio.Layer
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 rectangle 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 vsoLayer name is """ & vsoLayer.Name & "."""
End Sub
Applies to | Shape object
See Also | Layer object | LayerCount property