レイヤー表示の切り替え

Private Sub UIToolControl1_KeyDown(ByVal keyCode As Long, ByVal shift As Long)
    If Chr(keyCode) = "1" Then
    
        Call ChangeVisibleLayer("新規グループレイヤ") 'レイヤ名
    
    End If

End Sub


Public Sub ChangeVisibleLayer(Optional LayerName As String = "")

    If LayerName = "" Then
        LayerName = InputBox("表示を切り替えるレイヤを入力してください。", "レイヤ表示切り替え")
        If LayerName = "" Then Exit Sub
    End If
    
    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument
    
    If pMxDocument.FocusMap.LayerCount = 0 Then Exit Sub
    
    Dim pEnumLayer As IEnumLayer
    Set pEnumLayer = pMxDocument.FocusMap.Layers(Nothing, False)
    pEnumLayer.Reset
    
    Dim pLayer As ILayer
    Set pLayer = pEnumLayer.Next
    
    Do Until pLayer Is Nothing
    
        If pLayer.Name = LayerName Then
                 pLayer.Visible = Not pLayer.Visible
        End If
        Set pLayer = pEnumLayer.Next
    Loop
    
    '再描画
    pMxDocument.UpdateContents
    pMxDocument.ActiveView.Refresh

End Sub