Layers.Add method (Visio)

Adds a new Layer object to a Layers collection.

Syntax

expression.Add (LayerName)

expression A variable that represents a Layers object.

Parameters

Name Required/Optional Data type Description
LayerName Required String The name of the new layer.

Return value

Layer

Example

The following macro shows how to add a Layer object to the Layers collection.

Public Sub AddLayer_Example() 
 
 Dim vsoDocument As Visio.Document 
 Dim vsoPages As Visio.Pages 
 Dim vsoPage As Visio.Page 
 Dim vsoLayers As Visio.Layers 
 Dim vsoLayer As Visio.Layer 
 
 'Add a document based on the Basic Diagram template. 
 Set vsoDocument = Documents.Add("Basic Diagram.vst") 
 
 'Get the Pages collection and add a page to the collection. 
 Set vsoPages = vsoDocument.Pages 
 Set vsoPage = vsoPages.Add 
 
 'Get the Layers collection and add a layer named "MyLayer" 
 'to the collection. 
 Set vsoLayers = vsoPage.Layers 
 Set vsoLayer = vsoLayers.Add("MyLayer") 
 
End Sub

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.