Empty Immediate Window - VBA Code Help

Juggler_IN

Active Member
Joined
Nov 19, 2014
Messages
349
Office Version
  1. 2003 or older
Platform
  1. Windows
I have this VBA code to empty immediate window. On a standalone basis it works just fine. But, when I call it from another Sub then it clears the output from that Sub too inspite of the fact that I am calling the DoEmpty Sub before generating the new output. Any help?
VBA Code:
Public Sub DoEmpty()

    SendKeys "^g", True    ' Go to the VBE Immediate Window
    SendKeys "^a", True    ' Select content
    SendKeys "{del}"    ' Delete content
    SendKeys "{f7}"    ' Go back to VBE Project Window

End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Sendkeys generally isn't executed until your procedure finishes. You could always fudge it by just outputting a few hundred lines of ""
 
Upvote 0
VBA Code:
Sub Debug_Clear()
    ' Clear the Immediate Window.
    ' 3/16/19 From StackOverflow "Use VBA to Clear Immediate Window?" WML

    Application.VBE.Windows("Immediate").SetFocus
    Application.SendKeys "^g ^a {DEL} {HOME}"
    
End Sub ' Debug_Clear
 
Upvote 0
Last example of code doesn't work any more.

Now when I execute the Immediate Clear code, if I put a code stop in VBA on the next Debug.Print Statement in my code and then execute the code the Debug.Print statement prints properly.

However, if I set a stop on the line after the Debug.Print, no data from the Debug.Print statement is displayed.

My work around is to print a row of "=" characters across the page to mark a new top. But I would like to know if anyone is having the same problem I am or even better has figured out a work around.

Many thanks, Mac
 
Last edited:
Upvote 0
Last example of code doesn't work any more.

Now when I execute the Immediate Clear code, if I put a code stop in VBA on the next Debug.Print Statement in my code and then execute the code the Debug.Print statement prints properly.

However, if I set a stop on the line after the Debug.Print, no data from the Debug.Print statement is displayed.

My work around is to print a row of "=" characters across the page to mark a new top. But I would like to know if anyone is having the same problem I am or even better has figured out a work around.

Many thanks, Mac

Hi thanks for this. You put me on the right track.
Why not keep it simple and do this:

Application.VBE.Windows("Immediate").Visible = True
Debug.Print vbLf & Format(Now(), "dd-mmm-yyyy HH:mm:ss")

And for good measure here is the link to the article you referenced:
 
Upvote 0
While that
Hi thanks for this. You put me on the right track.
Why not keep it simple and do this:

Application.VBE.Windows("Immediate").Visible = True
Debug.Print vbLf & Format(Now(), "dd-mmm-yyyy HH:mm:ss")

And for good measure here is the link to the article you referenced:
for me: While that works to put a time stamped line in the Immediate window it is not clearing the Immediate window so that fresh debug messages can be output the next time you run the code. I am sticking with the manual Select ALL, Del process. It is a pain though.
Stephen G6SGA
 
Upvote 0

Forum statistics

Threads
1,216,126
Messages
6,129,007
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top