Excel VBA
Introduction To VBA: Macros And Automation Part 1
Language Basics
Overivew
Before we open the Visual Basic for Applications editor, it is important to cover the basics of the language we will be using. We will not be covering all the language tropes which exist, but only those which are central to a basic understanding of how we will need to structure our Macros.
For those who are undertaking VBA as their first programming language, the following section will discuss the general terminology that is used across different languages to explain or reference specific aspects of code. These terms are considered to be universal and should not change in definition regardless of programming language. This section is not necessary for those with more exposure to programming, these terms should already be well defined.
We will then be looking at the keywords which are most prevalent in VBA, and provide links to Microsoft resources which contain the most up to date information on VB and VBA whenever possible.
Keywords are specific terms which hold a meaning beyond the label they are given. They are references which instruct a computer to perform a specific action, or to treat information in a specified way. Some are shorthand for the longer word which describe the functionality they are responsible for, others are more explicit in their naming convention. Many keywords can be shared between languages, although they may not necessarily operate in the same way.
Data types are a subset of keyword which denote the format information is stored in. When using Excel normally, the system will scan the contents of a cell and assign it a data type automatically. This is done without any interference from the user. They can then change the data type should they see fit. Although this is normally limited to changes between a text data type and a numerical data type, where the exact type is not a choice users have access to.
By contrast, in VBA data types need to be explicitly stated within the code for any variable or input to be accepted. As with other programming languages, there is not just one data type for numbers, or text, or to reference or control other objects. While many of these data type have names which remain consistent across languages, there are exceptions and limitations and some languages may not utilize certain data types.