Add this to the Enviorment Events in the MacroIDE
VB Code:
  1. Private blnLoading As Boolean
  2.  
  3.     Private Sub DocumentEvents_DocumentOpened(ByVal Document As EnvDTE.Document) Handles DocumentEvents.DocumentOpened
  4.  
  5.         blnLoading = True
  6.  
  7.     End Sub
  8.  
  9.     Private Sub WindowEvents_WindowActivated(ByVal GotFocus As EnvDTE.Window, ByVal LostFocus As EnvDTE.Window) Handles WindowEvents.WindowActivated
  10.         If blnLoading Then
  11.             DTE.ExecuteCommand("Edit.CollapsetoDefinitions")
  12.             blnLoading = False
  13.         End If
  14.  
  15.     End Sub