For example, in this code we’re looking for the font color of cell A1. The Locals Window is shown for comparison.įinding information through the Locals Window becomes even more burdensome when you are working with large objects that have several properties or that may contain child objects. In the image above, the VBA Immediate Window is used to query the values of variables x and agg while the macro is paused. To find the value of a variable, say in the middle of this execution, simply type a question mark followed by the variable name: ![]() You can do the same thing in the Locals Window and the Watch Window, but if you have several variables instantiated, it might be hard to find yours. One of the big benefits of the Immediate Window is the ability to check the value of a variable when execution is paused (in debug mode). The VBE with the Immediate Window undocked With that said, it’s still in the same layer as the VBE, so if you put the VBE behind the Excel window, you won’t be able to see the Immediate Window. Using it undocked makes it feel more independent, and you can use it while the rest of the VBE is hidden offscreen. Once you open it, you will get a blank box that says “Immediate” in the upper left corner. The View Menu Dropdown with the VBA Immediate Window option highlighted Note the shortcut only works when the VBE is in focus (otherwise you will get the Go To dialog box in Excel). The commonly assigned keyboard shortcut is Ctrl+G. ![]() If you cannot see it in your default VBE view, you can add it by navigating to View > Immediate Window. The first step to successfully using the VBA Immediate Window is actually locating it. Mastering the Immediate Window really will make your next VBA project a lot easier. Most people only use the VBA Immediate Window to view the output of the Debug.Print statement, but this tutorial is going to prove that it’s far more powerful than that. The Immediate Window is located in the VBE ( VB editor), and it allows the user to immediately evaluate expressions, execute blocks of code, change variables during execution, and look at the information output from Debug.Print statements found throughout the code. ![]() ![]() In this tutorial, we’re going to teach you how to get the most out of the VBA Immediate Window.
0 Comments
Leave a Reply. |