属性テーブルのソート順でレコードを取得

'属性テーブルのソート順でレコードを取得
Sub GetSortedRows()
    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument
    
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = pMxDocument.FocusMap.Layer(0)
    
    Dim pTableWindow  As ITableWindow
    Set pTableWindow = New TableWindow
    
    Dim pTableWindow3 As ITableWindow3
    Set pTableWindow3 = pTableWindow
    
    Set pTableWindow.Application = Application
    Set pTableWindow.FeatureLayer = pFeatureLayer
    
    If pTableWindow.IsVisible = False Then
        pTableWindow.Show (True)
    End If
    
    Dim pExistingTableWindow As ITableWindow
    Set pExistingTableWindow = pTableWindow3.FindViaLayer(pFeatureLayer)
    
    Dim pTableControl As ITableControl3
    Set pTableControl = pExistingTableWindow.TableControl
    
    Dim i As Long
    For i = 1 To pExistingTableWindow.FeatureLayer.FeatureClass.FeatureCount(Nothing)
        Call pTableControl.SetCurrentRow(False, i)
        Debug.Print "i:" & i, "OID:" & pTableControl.GetCurrentRow(True)
        
    Next i

End Sub