Learning Unit 7
Learning Unit 7
An Introduction to Aspects
25
7.1 Introduction
In study units 4 to 6, you learnt how to work with formulas, functions, data presentation,
and spreadsheet security. The foundations learnt in AIN1501 as well as study units 4
to 6 has provided you with a solid foundation for this study unit and the study units to
follow within this topic.
The purpose of this study unit is to build on your Excel knowledge by introducing you
to an additional tab found within the Microsoft Excel ribbon, known as the “Developer”
tab. Gaining an understanding of the tools available in this tab is necessary in
preparing to learn a new skill, in the format of coding. The study unit will also introduce
you to the basic principles of VBA (Visual Basic for Applications), where you will be
exposed to some aspects that you will need for macros and the actual coding process.
Adding an additional and relevant skill to your arsenal is always beneficial in the long
run, and so our journey begins in this environment of basic programming.
This icon indicates that you need to click on the link to view a brief
video file.
Let’s start with a simple example. I give you the following instruction:
I think most of you do not know what I am instructing you to do here 😊😊.
Now you understand the instruction given and will perform the task by making me
some coffee.
But what did you need to perform this task? You had the instruction in Latin, a Latin
translator and the instruction given in a language you could understand, which was
English. Our communication with computers is the same.
Computers communicate in binary code (a language consisting out of 0’s and 1’s).
Let’s illustrate this: a computer wants to communicate to you and displays the
following: 01001000 01100101 01101100 01101100 01101111 00100001. According
to Zych (2015) the computer is telling you “Hello”.
If you want to learn more on binary code, you can read the article by
Zych (2015) by clicking on the link below.
Note: This article is not part of the syllabus and therefore not
examinable.
Just like in the case with the Latin phrase, we need interpreters to interpret instructions
and communications between us and computers. Programming languages act as
these interpreters. So, if I tell a programming language to give a computer an
instruction to copy cells in a sheet of a spreadsheet and to copy it to another workbook,
the computer will comply. Fortunately, I do not have to communicate this directly to
the computer using 0s and 1s. However, you get different interpreters, which in this
case is your programming languages.
The problem is that each programming language has its own rules (or syntax). For us
to communicate efficiently with a computer we need to know the programming
language in such a way that we can communicate with it efficiently.
There are different programming languages on the market. Popular languages are
Java, Python, C,C++ and VBA. As you were introduced to a Microsoft-based solution
called Microsoft Excel (Excel) in AIN1501 and AIN2601, we will now teach you to
create a solution using VBA (Visual Basic for Applications).
7.2.1 Making use of VBA
VBA is a powerful programming language built into Excel, which can be used to
automate routine and repetitive tasks, create custom worksheet formulas, and develop
Excel-based applications for other users (Alexander & Kusleika, 2022:867). The focus
of this module will be to use VBA to automate routine and repetitive tasks. Creating
custom worksheet formulas and form-based solutions is outside the scope of this
module.
Note that VBA is not available on the web version of Microsoft Excel. You will need to
use the desktop version of Microsoft Excel 365 to work with VBA.
• Open Excel.
• Right-click on the ribbon and select "Customize the Ribbon". You will see the
following:
Figure 7.1: Customise the ribbon options
If we’re going to be using the “Developer” tab, then we need to know what it is
actually used for as well as be able to navigate our way around the “Developer” tab.
Excel is among the most valuable tools used by finance professionals. It allows them
to conduct a financial analysis of companies based on different parameters or build
intricate financial models to help investors improve their investment portfolios and
guide their decisions regarding financial markets.
Imagine you are a manager of a financial modelling department, and tomorrow is the
earnings release date for multiple companies. Would you be able to cope with all the
work on Microsoft Excel? Absolutely not! Working 10-12 hours continuously under
intense pressure is no joke. That's why it is important to use Microsoft Excel
efficiently and maximise its effectiveness using the various simple but powerful tools
that it provides.
The Microsoft Excel “Developer” tab helps in creating reports, analysing large
volumes of data, generating reports, etc. The spreadsheet application makes it easy
for financial analysts, investment bankers and portfolio managers to make decisions
with ease.
When the “Developer” tab is activated in Microsoft Excel, they carry out more
advanced functions such as designing forms, writing code, creating macros, as well
as importing and exporting XML file formats. It automates your daily repetitive work.
The relevant tools within the “Developer” tab will be elaborated on at each
appropriate section to which the tools apply. The tools that will be discussed are as
follows:
If you click on “Visual Basic”, you will go to the Visual Basic Interactive Development
Environment. We refer to this environment in short as the Visual Basic Editor (VBE).
The Visual Basic Editor (VBE) is the first icon in the “Developer” tab, which is one of
the core icons that will be used, when you begin to code. Clicking on the Visual
Basics from the Developer tab will open a window that will allow you to write your
own code to automate a task in Excel. But first, you need to add a module to write
the code. A VBA module acts as a vessel for your code, keeping it all together. The
creation of modules will be discussed in the next study unit (study unit 8).
The VBE is like a workbench when doing woodwork. All the tools are here to write your
code (sometimes also refer to as macros). The VBE will become your new best friend
when automating solutions in Microsoft Excel. If your screen does not look exactly like
Figure 7.5, don’t stress. We will make sure you are able to access the most important
areas in your VBE throughout the rest of this study unit.
• Click on “Tools” and select “Options”. You will see the following:
Figure 7.6: VBE Options
• Make sure that all the boxes are ticked like displayed in Figure 7.6. Press
“OK”.
• Now click on “View”, “Toolbars” and make sure that Edit and Standard are
selected. If not selected, select them.
Project
window
Code window
Properties
window
Immediate window
Project window
The project window displays a tree diagram that shows every workbook
currently open in Excel (Alexander & Walkenbach, 2019:33). Note that your
modules are also displayed. Modules are units where VBA code are stored.
Properties window
This represents the properties of the selected object selected. In Figure 7.7, it
is the properties of Module1. You will see a (Name) property, where we can
change the name of Module1.
Code window
The Code window is where you add your VBA code (Alexander & Walkenbach,
2019:33). The code window makes use of colours to assist you in writing your
code. If text is blue, it is normally reserved words used in VBA. Green text
indicates comments, while red text indicates that an error was made in the
code.
Immediate window
The immediate window returns the results of statements you have typed in the
immediate window (Etheridge, 2007:26). It is very useful for testing VBA
statements, especially when you want to test code or solve an error in your
code. We will discuss the Immediate window later in the study unit.
Under the Macro options, users can also open the Visual Basic Editor (VBE) Editor to
create, edit, and record macros that can perform frequent or repetitive tasks in MS
Office applications. While users can still create macros in the traditional manner,
writing a macro from the VBE provides more flexibility, and users can complete more
complicated tasks using VBA.
The “Record Macro” function in the “Developer” tab is used for recording the macro,
and will be referred to when this action is practically required in the study unit 8.
Relative reference macros record an offset from the active cell. Such macros will be
useful if you have to repeat the steps at various places in the worksheet. Macros are
usually recorded in absolute mode, where it will refer to the same cells as the initially
recorded macro.
Figure 7.10: The Macro settings of the Trust Centre dialog box
Microsoft (Microsoft.com) provides the following guidance to select the correct option
on Macro settings:
Disable all macros without notification
This option should be selected if you don’t trust macros. Macros will not work in these
documents.
Disable all macros with notification
Click this option if you want macros to be disabled, but a notification should appear to
inform you that there are macros present in the document. If you trust the document,
then you can enable the macros from the message received.
Disable all macros except digitally signed macros
This setting is the same as the “Disable all macros with notification” option, except that
if the macro is digitally signed by a trusted publisher. Therefore, the macro can run if
you have already trusted the publisher. If you have not trusted the publisher, you are
notified. Note that all unsigned macros are disabled without notification.
Enable all macros (not recommended, potentially dangerous code can run)
Click this option to allow all macros to run. Using this setting makes your computer
vulnerable to potentially malicious code and is not recommended.
It is the view of the AIN2601 lecturers that the “Disable all macros with notification”
should be selected. If you distribute a macro solution to another user, then ask the
user to select “Enable Content” if he/she receives the notification. The notification the
user will receive is illustrated in Figure 7.11 below.
7.3.5 Add-ins
Add-ins are additional programs that users can install to get additional features,
functionalities, and commands in Excel. When a user installs Excel for the first time,
add-ins are not immediately available, and users need to install and activate them first.
Add-ins and Excel Add-ins allow web technologies to interact with Office applications
across different platforms. They are similar to Google extensions and were previously
called Office Apps (now referred to as Office Add-ins). They replicate the role of an
assistant helping you with tasks that Office cannot do easily.
Analytical tools for statistics as well as automation add-ins can be included in the
workbooks by clicking on Excel add-ins and marking ticks on the required tool packs.
Some of the Excel add-ins are built within the application, such as Analysis Toolpak
and Solver, while others are developed by solution providers to perform specific
functions. Users can also create an add-in by writing or recording the code in a module,
saving it as an Excel add-in, and then inserting the add-in to the Quick Access toolbar.
COM Add-ins present the developer with a way to extend the functionality of Office
applications for custom tasks. COM Add-ins are typically used to automate Excel in
response to a click of a CommandBar button, a form or dialog box, or some other
event specific to Excel such as opening or closing workbooks or entering data on
worksheets. COM Add-in functions cannot be directly called from cell formulas in
worksheets.
Check Box: also called tick box or selection box, is a control tool that displays the
selected option using a checkmark in a little square box. The check box is used to
select or deselect single and/or multiple given options.
Command buttons or push buttons are used to draw buttons that execute or run an
assigned macro. If a workbook contains multiple macros, it can sometimes be
inconvenient to run the desired macro from the Developer tab or by using Alt + F8 and,
in such instances, creating a command button and assigning the macro to it eases the
task for an Excel user.
Combo box is an interactive tool that allows you to add items of your choice and select
them via the drop-down list. The item can be selected by either typing in the text or by
clicking on it from the drop-down list.
Image Control is used to embed a picture such as JPEG or GIF allowing us to crop,
move and resize it while letting us display pictures as part of the data in the
spreadsheet; for instance, when using a company logo and employee photos on the
employee attendance spreadsheets.
List Box: Like a combo box, a list box allows you to add items and lets you select a
value from a set of many values. Despite the similarity in function, they are different in
their appearances. A list box is scrollable and displays more values as opposed to a
combo box with only one value. A combo box will allow users to write text in the box,
while a list box does not contain a text box to specifically search for an item.
Option Button: An option button, or also called the radio button, is a graphical control
tool that accepts only a single response from the user from the several options in the
set. Any attempt to select another option automatically deselects the previous one,
meaning that option buttons are mutually exclusive, allowing only one response from
the user. Like a coin toss that will yield either a head or a tail, an option button will
allow only one response from the user.
Scroll Bar: The scroll bar allows you to increase or decrease the value of the linked
cell. You can easily navigate through a large list of items by using horizontal or vertical
scroll bars as well as the up-and-down arrow. The interactive nature of the scroll bar
allows a user to scroll for selecting the values from the given list rather than manually
typing the value, thereby saving time for the user.
Spin Button: Spin buttons are similar to scroll bars, allowing the user to make
increments or decrements of value by clicking on the up and down arrow, respectively.
This helps to quickly change a value or change a range of values such as number
increments, date, or time.
Text Box: A text box allows the user to insert text in them. By default, it allows you to
only add a single line of text; however, you can modify it to hold more information. It
can be static or dynamic, depending on the type of input you expect from other users.
For example, you can make the text boxes dynamic by creating a user form that will
accept age only as a number. Any alphabetic response will be rejected by the form
built in the spreadsheet.
If you have worked on HTML codes before, you might be aware that the two tags
<title> and <body> respectively display the text in different sections of the webpage.
On the other hand, irrespective of the position, an XML tag allows you to store the data
using self-descriptive tags or language that best suits the application. For example, a
part of XML data written as <phone>212-877-298X</phone> in notepad means that
an element is a phone number as described in the XML tag.
You can import data that’s in XML format into your spreadsheet.
Figure 7.14: XML data onto a spreadsheet
You can export your data in XML format so that other applications can use the XML
formatted data.
7.4 Summary
In this study unit, we looked at an introduction to VBA and its purpose within our
environment as a student. We also took a closer look at what VBA is, and started off
by navigating our way around the ribbon in Microsoft Excel to access the “Developer”
tab where VBA applications are located.
We also took a look at the VBE, which creates the environment for future coding to
take place and serves as our workbench for projects with VBA.
In the next study unit, we will delve deeper into VBA by looking at macros and how to
write some code.
REFERENCES
Alexander, A. & Kusleika, D. 2022. Microsoft Excel 365 Bible. The comprehensive
tutorial resource. 1st edition. John Wiley & Sons. New Jersey.
Alexander, A. & Walkenback, J. 2019. Excel VBA Programming for dummies. 5th
edition. John Wiley & Sons. New Jersey.
Etheridge, D. 2007. Microsoft Office Excel 2007 Programming. 1st edition. Wiley
Publishing, Inc.