ArcToolbox のツール数をカウント

'ツールボックス内のツール数カウント
Public Sub GetArcToolboxCount()

    'Toolboxファイル
    Dim strSystemToolboxName As String
    strSystemToolboxName = InputBox("システム ツールボックスのファイル名を入力してください。", , "Spatial Analyst Tools.tbx")
    
    If strSystemToolboxName = "" Then Exit Sub
    
    'ToolboxWorkspaceFactoryの作成
    Dim pToolboxWorkspaceFactory As IWorkspaceFactory
    Set pToolboxWorkspaceFactory = New ToolboxWorkspaceFactory
    
    'ToolboxWorkspaceの作成
    Dim pToolboxWorkspace As IToolboxWorkspace
'    Set pToolboxWorkspace = pToolboxWorkspaceFactory.OpenFromFile("C:\Program Files\ArcGIS\ArcToolbox\Toolboxes", 0)
    Set pToolboxWorkspace = pToolboxWorkspaceFactory.OpenFromFile("C:\Programs\ArcGIS\arcexe9x\Toolboxes\", 0)
    
    '名前によるToolboxの取得
    Dim pGPToolbox As IGPToolbox
    Set pGPToolbox = pToolboxWorkspace.OpenToolbox(strSystemToolboxName)
    
    Dim pEnumGPTool As IEnumGPTool
    Set pEnumGPTool = pGPToolbox.Tools
    
    pEnumGPTool.Reset
    
    Dim pGPTool As IGPTool
    Set pGPTool = pEnumGPTool.Next
    
    Dim i As Long
    i = 0
    
    'ループ
    Do Until pGPTool Is Nothing
        i = i + 1
        
        Set pGPTool = pEnumGPTool.Next
    Loop
    
    MsgBox i, , strSystemToolboxName
    Debug.Print strSystemToolboxName, i
  
End Sub

'  Dim pUID As New UID
'  pUID.Value = "esriGeoprocessingUI.ArcToolboxExtension"
'
'  Dim pArcToolboxExtension As IArcToolboxExtension
'  Set pArcToolboxExtension = Application.FindExtensionByCLSID(pUID)
'
'  Dim pArcToolbox As IArcToolbox
'  Set pArcToolbox = pArcToolboxExtension.ArcToolbox
'
'    Dim pGPToolboxFactory As IGPToolboxFactory
'    Set pGPToolboxFactory = New GPToolboxFactory

'  Dim pGPToolbox As IGPToolbox
'  Set pGPToolbox = pGPToolboxFactory.OpenFromFile("C:\Program Files\ArcGIS\ArcToolbox\Toolboxes\3D Analyst Tools.tbx")