AnsweredAssumed Answered

Select Layer in TOC using VBA

Question asked by lopelm on Mar 7, 2012
Latest reply on Mar 13, 2012 by lopelm
Hi there!

I am trying to have a layer in the TOC selected by its name. Say I have a layer named "Roads", I would like to have this layer selected in the TOC, but I don't want to check its view, just have it selected (in the same as when you click on a layer and it turns blue and remains selected). ¿Is it possible?

Thank you!

Here you are a piece of vba:

Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Dim pMapa As IMap
Set pMapa = pDoc.FocusMap
Dim pCapa As ILayer
Set pCapa = pDoc.SelectedLayer

If pCapa Is Nothing Then
MsgBox "No layers selected"
MsgBox pMapa.Layer(0).Name 'First layer name in the TOC
'How do I select this layer?
MsgBox pCapa.Name 'Layer selected
If pCapa.View = False then
pCapa.View = True 'It turn on its view but I would like tu select it
End if
End If