Macro to Clear the Immediate Window - Visual Studio 2005

In Visual Studio 2005, it can be useful to clear the Immediate Window at the start of a program execution. This can be accomplished by first implementing the following code into the code for your Visual Studio macros. Then, by setting a breakpoint on the first line of the program and specifying When Hit for the breakpoint to Run a macro > Macros.MyMacros.ImmediateWindow.ClearAndActivate, the Immediate Window will be cleared every time you start the program.

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics

Public Module ImmediateWindow

    'GUID for the Immediate Window
    Public Const GUID As String = "{ECB7191A-597B-41F5-9843-03A4CF275DDE}"

    Public Sub Clear()

        Dim win As Window = DTE.ActiveWindow
        DTE.Windows.Item(GUID).Activate()
        DTE.ExecuteCommand("Edit.SelectAll")
        DTE.ExecuteCommand("Edit.ClearAll")
        win.Activate()

    End Sub

    Public Sub ClearAndActivate()

        DTE.Windows.Item(GUID).Activate()
        DTE.ExecuteCommand("Edit.SelectAll")
        DTE.ExecuteCommand("Edit.ClearAll")

    End Sub

    Public Sub Activate()

        DTE.Windows.Item(GUID).Activate()

    End Sub

End Module