View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
joeu2004 joeu2004 is offline
external usenet poster
 
Posts: 2,059
Default Immed Win: how to home down and clear?

In a VBA macro, how can I clear the Immediate Window before doing a series
of Debug.Prints?

How can I home down or append to the bottom of the Immediate Window?

I would like this to work whether or not the Immediate Window is open.

I am using Excel 2003 on Win XP SP3.

I can do this manually, of course. But I would like the macro to do it.

In response to a similar question in Aug and Sep 2008, Bob Phillips offered:

Sub ClearImmediateWindow()
Application.SendKeys "^g ^a {DEL}"
End Sub

CharlotteE followed up (in Aug), saying that it needed to be preceded with:

Application.VBE.MainWindow.Visible = True
Application.VBE.MainWindow.SetFocus

But when I try to put that together:

1. I get an error on the first .Visible statement, namely "method VBE of
object _Application failed".

2. Without the Application.VBE statements, the .SendKeys clears the editor
pane, not the Immediate Window.

(Unless I open the Immediate Window manually and execute the macro from
the Immediate Window. Not what I want.)

With the Immediate Window closed (or open, at my discretion) and with the VB
editing pane visible, I want to put the cursor in the following macro and
press F5 to start execution.

Sub Doit()
Dim x as Double ...etc...
' clear Immediate Window here
Application.SendKeys "^g ^a {DEL}"
For i = ...
....statements includig Debug.Print...
Next i
End Sub

It might relevant to note that I have the Immediate Window in a mode where
it is "floating" (not docked?). That is, it is not the bottom pane of the
VBA window, which I think is its default position. The Immediate Window
partially overlays the VBA window when both are open.