Excel Macro Tips – Run An Excel Macro From Immediate Window

by Emily Smith
0 comments 95 views
A+A-
Reset

[ad_1]

This article will explain how look to use the Immediate Window in the VBA debugging environment. This environment can be used as a type of scratchpad or sand box area and has many uses as well as debugging code.

If you cannot see the Immediate Window, you just need to enable it. It really simple.

  • Open the Visual Basic Editor
  • View
  • Immediate Window

Or if you are mad for shortcuts, then 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

You are all set. The window looks quite bland and basic at first glance but it is really really useful for example you can-

  • Get Some Information About Your Current Excel Work book

We can ask questions in the Immediate Window and expect an answer, we just need to use a questions mark ‘?’. For example by typing in the window ?Worksheet.Count we are correctly for example in my work book told that there are 4 worksheets. Cool.

  • Execute A Line Of VBA Code And Get Immediate Results

You can also just execute one piece of VBA code from the Immediate Window. Just remove the? from the beginning of your statement and the code will run. Let’s take a look at an example. We can make all hidden worksheets visible by typing this code in the Immediate Window.

For Each ws In Sheets: ws.Visible = True:Next

This piece of code will loop through all of the worksheets and set their visible property to TRUE. Great Job!. Hopefully this gives you a taste of the power of the immediate window.

  • Run A Macro From the Immediate Window

So, as stated 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 to again that will un-hide all of the worksheets in my workbook or making then visible (however you prefer to say it!).

O named this macro Unhide_Multiple_worksheets.

All I need to do is type the name of the macro into the Immediate Window, hit return and the macro will run. Want to try another?.

Other Ways To Run A Macro

  • Hit F5
  • Hit the Run Command Button In the VB Editor in Excel.

[ad_2]

Source

You may also like

Leave a Comment