Building, calibrating and QC-ing linear referencing routes can add many layers to your arcmap project. Other projects and processes have the same issue: too many layers to manage with just mouse clicks.
If you keep your layer names consistent, it is easy to turn them on, off, or delete them from the ArcMap table of contents (TOC) programatically.
The code example below shows how to remove layers from the TOC using a search string. It also removes standalone tables too.
Public Sub removeLayersTables()
Dim searchStr As String searchStr = "0015P"
Dim pMxDoc As IMxDocument Dim pMap As IMap Dim pTC As ITableCollection Dim pDS As IDataset Dim x As Integer
Set pMxDoc = ThisDocument Set pMap = pMxDoc.FocusMap Set pTC = pMap
For x = pMap.LayerCount - 1 To 0 Step -1 If InStr(pMap.Layer(x).Name, searchStr) > 0 Then 'pMap.Layer(x).Visible = false pMap.DeleteLayer pMap.Layer(x) End If Next x
For x = pTC.TableCount - 1 To 0 Step -1 Set pDS = pTC.Table(x) If InStr(pDS.Name, searchStr) > 0 Then pTC.RemoveTable pTC.Table(x) End If Next x