アクティブなデータ フレーム内の全てのフィーチャ レイヤーから指定したフィールド表示を切り替え

Sub ShowHideField()

    'フィールド名の設定
    Dim vrnFieldName As Variant
    vrnFieldName = Array("City.Shape_Length", _
                         "City.Shape_Area", _
                         "CITY_H17_copy.ObjectID", _
                         "CITY_H17_copy.KEY_CODE", _
                         "CITY_H17_copy.Shape_Length", _
                         "CITY_H17_copy.Shape_Area")
    
    Dim pMxDocument As IMxDocument
    Dim pMap As IMap
    Dim pEnumLayer As IEnumLayer
    Dim pLayerFields As ILayerFields
    Dim pFieldInfo As IFieldInfo
    Dim i As Long
    Dim lngLayerIndex As Long
    
    'MxDocumentの取得
    Set pMxDocument = ThisDocument
    
    'Mapの取得
    Set pMap = pMxDocument.FocusMap
    
    'Layerリストの取得
    Set pEnumLayer = pMap.Layers()
    
    'FeatureLayerの取得
    Set pLayerFields = pEnumLayer.Next
    
    Do Until pLayerFields Is Nothing
        
        'インデックス番号の取得
        For i = 0 To UBound(vrnFieldName)
            lngLayerIndex = pLayerFields.FindField(vrnFieldName(i))
            Set pFieldInfo = pLayerFields.FieldInfo(lngLayerIndex)
            pFieldInfo.Visible = Not pFieldInfo.Visible
        Next i
        
        Set pLayerFields = pEnumLayer.Next

    Loop
    
    MsgBox "Done!"

End Sub