Page.Layers 屬性 (Visio)
會傳回 物件的 Layers 集合。 唯讀。
運算式。層
表達 代表 Page 物件的變數。
圖層
下列的 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 支援與意見反應。