名前からレイヤを取得する


Function GetFeatureLayerByName(LayerName As String) As ILayer
Dim i As Integer
Dim mylayer As ILayer
Dim myLayer2 As ILayer
Dim pMap As IMap
Dim pMxDocument As IMxDocument

Set pMxDocument = Application.Document
Set pMap = pMxDocument.FocusMap

For i = 0 To pMap.LayerCount - 1
If TypeOf pMap.Layer(i) Is FeatureLayer Then
Set mylayer = pMap.Layer(i)
'レイヤ名チェック
If mylayer.name = LayerName Then
Set myLayer2 = mylayer
Exit For
End If
End If
Next i

Set GetFeatureLayerByName = myLayer2

End Function