Use VBA to Clear Immediate Window?

前端 未结 16 988
刺人心
刺人心 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:40

    Marked answer does not work if triggered via button in worksheet. It opens Go To excel dialog box as CTRL+G is shortcut for. You have to SetFocus on Immediate Window before. You may need also DoEvent if you want to Debug.Print right after clearing.

    Application.VBE.Windows("Immediate").SetFocus
    Application.SendKeys "^g ^a {DEL}"
    DoEvents
    

    For completeness, as @Austin D noticed:

    For those wondering, the shortcut keys are Ctrl+G (to activate the Immediate window), then Ctrl+A (to select everything), then Del (to clear it).

提交回复
热议问题