Does anyone know how to clear the immediate window using VBA?
While I can always clear it myself manually, I am curious if there is a way to do this programmatically.
I'm in favor of not ever depending on the shortcut keys, as it may work in some languages but not all of them... Here's my humble contribution:
Public Sub CLEAR_IMMEDIATE_WINDOW()
'by Fernando Fernandes
'YouTube: Expresso Excel
'Language: Portuguese/Brazil
Debug.Print VBA.String(200, vbNewLine)
End Sub
I tested this code based on all the comments above. Seems to work flawlessly. Comments?
Sub ResetImmediate()
Debug.Print String(5, "*") & " Hi there mom. " & String(5, "*") & vbTab & "Smile"
Application.VBE.Windows("Immediate").SetFocus
Application.SendKeys "^g ^a {DEL} {HOME}"
DoEvents
Debug.Print "Bye Mom!"
End Sub
Previously used the Debug.Print String(200, chr(10))
which takes advantage of the Buffer overflow limit of 200 lines. Didn't like this method much but it works.
or even more simple
Sub clearDebugConsole()
For i = 0 To 100
Debug.Print ""
Next i
End Sub
Just checked in Excel 2016 and this piece of code worked for me:
Sub ImmediateClear()
Application.VBE.Windows("Immediate").SetFocus
Application.SendKeys "^{END} ^+{HOME}{DEL}"
End Sub