Is This Content Helpful?
How can we make this better? Please provide as much detail as possible.
Contact our Support Team
This sample shows how to get a reference to a layer by name rather than an index number.
Loop through all the layers in the map using IEnumLayer to check the layer names.
Code:
Sub GetLayerByName()
Dim pDoc As IMxDocument
Set pDoc = ThisDocument
' Get all the layers in the Map
Dim pEnumLayer As IEnumLayer
Set pEnumLayer = pDoc.FocusMap.Layers
' Loop through all the layers
Dim pLayer As ILayer
Set pLayer = pEnumLayer.Next
Do Until pLayer Is Nothing
If pLayer.Name = "STATES" Then
Exit Do
End If
Set pLayer = pEnumLayer.Next
Loop
End Sub