TOC のレイヤー凡例を展開・格納する方法

Public Sub ExpandTOCLegend()
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
    
    Dim pLegendInfo As ILegendInfo
    Set pLegendInfo = pMxDoc.FocusMap.Layer(0)
    
    Dim i As Long
    For i = 0 To pLegendInfo.LegendGroupCount - 1
        pLegendInfo.LegendGroup(i).Visible = Not pLegendInfo.LegendGroup(i).Visible
    Next i
    
    pMxDoc.UpdateContents
End Sub