Excel 2019 Bible

(singke) #1

Chapter 42: Introducing Visual Basic for Applications


42


FIGURE 42.4
Excel warns you if your workbook contains macros and you attempt to save it as a regular
Excel file.

Alternatively, you can save the workbook in the old Excel 97–2003 format (which uses an .xls extension) or the
newer Excel binary format (which uses an .xlsb extension). Both of these file formats can contain macros.


Looking at the Two Types of VBA Macros


A VBA macro (also known as a procedure) is usually one of two types: a Sub or a Function.
The next two sections discuss the difference.

What’s New in the Visual Basic Editor?
In a word, nothing. Beginning with Excel 2007, Microsoft made many changes to Excel’s user interface.
However, the VBE has remained untouched and seems like outdated software. The VBA language has
been updated to accommodate most of the new Excel features, but the VBE has no new features, and
the toolbars and menus work as they always have.

VBA Sub procedures
You can think of a Sub procedure as a new command that either the user or another macro
can execute. You can have any number of Sub procedures in an Excel workbook. Figure 42.5
shows a simple VBA Sub procedure. When this code is executed, VBA inserts the current
date into the active cell, applies a number format, makes the cell bold, sets the text color
to white, sets the background color to black, and adjusts the column width.
Free download pdf