Excel Visual Basic Variables, Part 2: Declaring and Naming Variables, Scope and Lifetime
Subscribe to continue reading
Subscribe to get access to the rest of this post and other subscriber-only content.
Subscribe to get access to the rest of this post and other subscriber-only content.
In this post, we will give you some more of the basic (forgive the pun) building blocks of the Visual Basic programming language. We will cover formulas, assigning values, logical comparison, constants, comments, and continuation lines. We conclude with two small examples. One of them demonstrates our first Error Trap. 1. Formulas We have already…
1. The Application Keyword Use “Application” to refer to Excel, e.g.: Application.ActivePrinter Name of the Active Printer.Application.Name Name of the program running (“Microsoft Excel”).Application.Path The path from which the program is running. 2. ActiveControl Instead of the name of a specific control (e.g. txtEdit), you can use the keyword ActiveControl. This will let your program refer…
It is difficult to make your program foolproof, because fools are so ingenious! Even so, one should make an effort to trap and handle errors. You should not let the program simply crash if there is a problem, whether due to bad data, faulty calculation, or whatever. This is what we call Error-Handling. Excel Visual…
The macros you recorded in the previous post are stored in an Excel file. To edit it you use what looks like a separate program, the Visual Basic Editor. Open it with the Developer ribbon (Code group) > Visual Basic Editor (Alt+F11). You will find newly-recorded macros under Modules in the explorer on the left…
In our previous post, we looked at connecting VBA code to command buttons on the Worksheet, the Quick Access Toolbar and the Ribbon. What about the other Form Controls: The Combo Box, List Box, or Check Box? How about Option Buttons, the Scroll Bar, the Spin button, the Label, etc.? That’s coming up in this…