ArcMap の TOC で選択したレイヤーのフィールド数をカウント

Public Sub FieldCount()
    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument
    
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = pMxDocument.SelectedLayer
    
    Dim pFeatureClass As IFeatureClass
    Set pFeatureClass = pFeatureLayer.FeatureClass
    
    MsgBox "選択レイヤのフィールド数 : " & pFeatureClass.Fields.FieldCount
    Debug.Print "選択レイヤのフィールド数 : ", pFeatureClass.Fields.FieldCount
    
End Sub