From: Mike Faulkner on
Hello

OS: Windows XP
Apps: Office XP

Does anyone know how to clear the immediate Window using VBA ie. 'Debug.clear'

Any suggestions would be appreciated. I understand that closing Word will
clear it but I am looking for a VBA option.

Regards
Mike
From: Karl E. Peterson on
Mike Faulkner <MikeFaulkner(a)discussions.microsoft.com> wrote:
> Does anyone know how to clear the immediate Window using VBA ie. 'Debug.clear'

It is possible from an add-in, using code like this:

Dim pWindow As VBIDE.Window
Set pWindow = VBI.Windows("Immediate")
If pWindow Is Nothing Then Exit Sub
If pWindow.Visible = True Then
pWindow.SetFocus
SendKeys ("^({Home})"), True
SendKeys ("^(+({End}))"), True
SendKeys ("{Del}"), True
End If
Set pWindow = Nothing

But you can only fake it from code that lacks a reference to the Extensibility
library. The Immediate window holds 200 lines of text, so doing this effectively
"clears" it:

Debug.Print String$(200, vbCrLf)

That just leaves the cosmetic issue, that the cursor is at the bottom rather than
the top of the window.
--
..NET: It's About Trust!
http://vfred.mvps.org