This article will explain how to use the Immediate window in the VBA debugging environment. This environment can be used as a type of sandbox or scratch area and has many uses, as well as debugging code.

If you can’t see the Immediate window, you just need to enable it. It really is simple.

  • Open the Visual Basic editor

  • View

  • Immediate window

Or if you are crazy about shortcuts, you can do the following:

  • ALT + 11 to open the Visual Basic Editor
  • CTRL + G to open the Immediate window and place the cursor in it

Are you ready. The window looks pretty bland and basic at first glance, but it’s really Really useful, for example, you can-

  • Learn about your current Excel workbook

We can ask questions in the Immediate window and wait for an answer, we just need to use a question mark ‘?’. For example, typing in the window ? Worksheet Account we are correctly for example in my workbook, it said there are 4 worksheets. Cold.

  • Run a line of VBA code and get immediate results

You can also run a piece of VBA code from the Immediate window. Just remove the? from the beginning of your declaration and the code will be executed. Let’s take a look at an example. We can make all the hidden worksheets visible by writing this code in the Immediate window.

For each ws in sheets: ws.Visible = True: Next

This code snippet will loop through all worksheets and set their visible property to TRUE. Great job !. Hopefully this will give you an idea of ​​the power of the immediate window.

  • Run a macro from the immediate window

So, as indicated at the top of this article, let’s run a macro from the Immediate window. It’s really simple again, we just need to type the name of the macro right there in the Immediate Window.

Here is the macro again that will either display all the worksheets in my workbook or make them visible (however you prefer to say it!).

Or called this macro Show_multiple_worksheets.

All I need to do is type the name of the macro in the Immediate window, hit return, and the macro will run. Do you want to try another?

Other ways to run a macro

  • Press F5

  • Press the Run command button in the VB Editor in Excel.

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *