Use VBA to Clear Immediate Window?

前端 未结 16 961
刺人心
刺人心 2021-01-30 00:19

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.

相关标签:
16条回答
  • 2021-01-30 00:51

    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
    
    0 讨论(0)
  • 2021-01-30 00:53

    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.

    0 讨论(0)
  • or even more simple

    Sub clearDebugConsole()
        For i = 0 To 100
            Debug.Print ""
        Next i
    End Sub
    
    0 讨论(0)
  • 2021-01-30 00:54

    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
    
    0 讨论(0)
提交回复
热议问题