Use VBA to Clear Immediate Window?

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

    SendKeys is straight, but you may dislike it (e.g. it opens the Immediate window if it was closed, and moves the focus).

    The WinAPI + VBE way is really elaborate, but you may wish not to grant VBA access to VBE (might even be your company group policy not to).

    Instead of clearing you can flush its content (or part of it...) away with blanks:

    Debug.Print String(65535, vbCr)
    

    Unfortunately, this only works if the caret position is at the end of the Immediate window (string is inserted, not appended). If you only post content via Debug.Print and don't use the window interactively, this will do the job. If you actively use the window and occasionally navigate to within the content, this does not help a lot.

提交回复
热议问题