このマクロは役に立ちますか?
http://kylefinley.net/archive/2006/02/02/37.aspx
Imports EnvDTE
Imports System.Diagnostics
Public Module Personal
Sub CollapseAll()
'DESCRIPTION: Collapse all the nodes in the project tree
' Get the the Solution Explorer tree
Dim oSolutionExplorer As UIHierarchy
oSolutionExplorer = DTE.Windows.Item(Constants.vsext_wk_SProjectWindow).Object()
' Check if there is any open solution
If (oSolutionExplorer.UIHierarchyItems.Count = 0) Then
Return
End If
' Get the top node (the name of the solution)
Dim oRootItem As UIHierarchyItem
oRootItem = oSolutionExplorer.UIHierarchyItems.Item(1)
Dim oChildItem As UIHierarchyItem
' Collapse each project node
For Each oChildItem In oRootItem.UIHierarchyItems
CollapseMe(oChildItem, oSolutionExplorer)
Next
' Select the solution node, or else when you click on the solution window
' scrollbar, it will synchronize the open document with the tree and pop
' out the corresponding node which is probably not what you want.
oRootItem.Select(vsUISelectionType.vsUISelectionTypeSelect)
End Sub
Sub CollapseMe(ByVal oRootItem As UIHierarchyItem, ByVal oSolutionExplorer As UIHierarchy)
Dim oChildItem As UIHierarchyItem
For Each oChildItem In oRootItem.UIHierarchyItems
CollapseMe(oChildItem, oSolutionExplorer)
Next
oRootItem.UIHierarchyItems.Expanded = False
' Added to deal with the Visual Studio bug
If (oRootItem.UIHierarchyItems.Expanded = True) Then
oRootItem.Select(vsUISelectionType.vsUISelectionTypeSelect)
oSolutionExplorer.DoDefaultAction()
End If
End Sub
End Module