レイヤー オブジェクトを配列に格納

Sub test()
    'マップドキュメントの取得
    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument
    
    'データフレームの取得
    Dim pMap As IMap
    Set pMap = pMxDoc.FocusMap
    
    'レイヤの配列宣言
    Dim pLayer() As ILayer
    ReDim pLayer(pMap.LayerCount - 1)
    
    '配列に格納
    Dim i As Long
    For i = 0 To pMap.LayerCount - 1
        Set pLayer(i) = pMap.Layer(i)
    Next i
    
    'レイヤの名前を表示
    For i = 0 To pMap.LayerCount - 1
        Debug.Print pLayer(i).Name
    Next i

End Sub