Share via


Layers.Add Method

Visio Automation Reference

Adds a new Layer object to a Layers collection.

Version Information
 Version Added:  Visio 2.0

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.

Visual Basic for Applications
  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

See Also