Introduction

As corporate IT departments have found themselves with long backlogs of requests, Excel users have discovered that they can produce the reports needed to run their businesses themselves using the macro language Visual Basic for Applications (VBA). VBA enables you to achieve tremendous efficiencies in your day-to-day use of Excel. VBA helps you figure out how to import data and produce reports in Excel so that you don’t have to wait for the IT department to help you.

What Is in This Book?

You have taken the right step by purchasing this book. We can help you reduce the learning curve so that you can write your own VBA macros and put an end to the burden of generating reports manually.

Reducing the Learning Curve

This Introduction provides a case study about the power of macros. Chapter 1, “Unleashing the Power of Excel with VBA,” introduces the tools and confirms what you probably already know: The macro recorder does not work reliably. Chapter 2, “This Sounds Like BASIC, So Why Doesn’t It Look Familiar?” helps you understand the crazy syntax of VBA. Chapter 3, “Referring to Ranges,” cracks the code on how to work efficiently with ranges and cells.

Chapter 4, “Looping and Flow Control,” covers the power of looping using VBA. The case study in this chapter demonstrates creating a program to produce a department report and then wrapping that report routine in a loop to produce 46 reports.

Chapter 5, “R1C1-Style Formulas,” covers, obviously, R1C1-style formulas. Chapter 6, “Creating and Manipulate Names in VBA,” covers names. Chapter 7, “Event Programming,” includes some great tricks that use event programming. Chapters 8, “Arrays,” and 9, “Creating Classes and Collections,” cover arrays, classes, and collections. Chapter 10, “Userforms: An Introduction,” introduces custom dialog boxes that you can use to collect information from a human using Excel.

Excel VBA Power

Chapters 11, “Data Mining with Advanced Filter,” and 12, “Using VBA to Create Pivot Tables,” provide an in-depth look at Filter, Advanced Filter, and pivot tables. Report automation tools rely heavily on these concepts. Chapters 13, “Excel Power,” and 14, “Sample User-Defined Functions,” include dozens of code samples designed to exhibit the power of Excel VBA and custom functions.

Chapters 15, “Creating Charts,” through 20, “Automating Word,” handle charting, data visualizations, web queries, sparklines, and automating Word.

Techie Stuff Needed to Produce Applications

Chapter 21, “Using Access as a Back End to Enhance Multiuser Access to Data,” handles reading and writing to Access databases and SQL Server. The techniques for using Access databases enable you to build an application with the multiuser features of Access while keeping the friendly front end of Excel.

Chapter 22, “Advanced Userform Techniques,” shows you how to go further with userforms. Chapter 23, “The Windows Application Programming Interface (API),” teaches some tricky ways to achieve tasks using the Windows API. Chapters 24, “Handling Errors,” through 26, “Creating Add-ins,” deal with error handling, custom menus, and add-ins. Chapter 27, “An Introduction to Creating Office Add-Ins,” provides a brief introduction to building your own JavaScript application within Excel. Chapter 28, “What’s New in Excel 2016 and What’s Changed,” summarizes the changes in Excel 2016.

Does This Book Teach Excel?

Microsoft believes that the ordinary Office user touches only 10% of the features in Office. We realize that everyone reading this book is above average, and MrExcel.com has a pretty smart audience. Even so, a poll of 8,000 MrExcel.com readers showed that only 42% of smarter-than-average users are using any 1 of the top 10 power features in Excel.

I regularly present a Power Excel seminar for accountants. These are hard-core Excelers who use Excel 30 to 40 hours every week. Even so, two things come out in every seminar. First, half of the audience gasps when they see how quickly you can do tasks with a particular feature, such as automatic subtotals or pivot tables. Second, someone in the audience routinely trumps me. For example, someone asks a question, I answer, and someone in the second row raises a hand to give a better answer.

The point? You and I both know a lot about Excel. However, I assume that in any given chapter, maybe 58% of the people have not used pivot tables before and maybe even fewer have used the Top 10 Filter feature of pivot tables. With this in mind, before I show how to automate something in VBA, I briefly cover how to do the same task in the Excel interface. This book does not teach you how to make pivot tables, but it does alert you when you might need to explore a topic and learn more about it elsewhere.

The Future of VBA and Windows Versions of Excel

Several years ago, there were many rumblings that Microsoft might stop supporting VBA. There is now plenty of evidence to indicate that VBA will be around in Windows versions of Excel through 2036. When VBA was removed from the Mac version of Excel 2008, a huge outcry from customers led to its being included in the next Mac version of Excel.

XLM macros were replaced by VBA in 1993, and 23 years later, they are still supported. Microsoft is making strides toward providing a JavaScript alternative to VBA, but it appears that Excel will support VBA for about another 23 years.

Versions of Excel

This fifth edition of VBA and Macros is designed to work with Excel 2016. The previous editions of this book covered code for Excel 97 through Excel 2013. In 80% of the chapters, the code for Excel 2016 is identical to the code in previous versions. However, there are exceptions. For example, the new AutoGroup functionality in pivot tables adds new options that were not available in Excel 2013.

Differences for Mac Users

Although Excel for Windows and Excel for the Mac are similar in terms of user interface, there are a number of differences when you compare the VBA environment. Certainly, nothing in Chapter 23 that uses the Windows API will work on the Mac. That said, the overall concepts discussed in this book apply to the Mac. You can find a general list of differences as they apply to the Mac at http://www.mrexcel.com/macvba.html. Development in VBA for Mac Excel 2016 is far more difficult than in Windows, with only rudimentary VBA editing tools. Microsoft actually recommends that you write all of your VBA in Excel 2016 for Windows and then use that VBA on the Mac.

Special Elements and Typographical Conventions

The following typographical conventions are used in this book:

Image Italic—Indicates new terms when they are defined, special emphasis, non-English words or phrases, and letters or words used as words.

Image Monospace—Indicates parts of VBA code, such as object or method names.

Image Bold monospace—Indicates user input.

In addition to these typographical conventions, there are several special elements. Each chapter has at least one case study that presents a real-world solution to common problems. The case study also demonstrates practical applications of topics discussed in the chapter.

In addition to the case studies, you will see Notes, Tips, and Cautions.


Note

Notes provide additional information outside the main thread of the chapter discussion that might be useful for you to know.



Tip

Tips provide quick workarounds and time-saving techniques to help you work more efficiently.



Caution

Cautions warn about potential pitfalls you might encounter. Pay attention to the Cautions; they alert you to problems that might otherwise cause you hours of frustration.


Code Files

As a thank-you for buying this book, we have put together a set of 50 Excel workbooks that demonstrate the concepts included in this book. This set of files includes all the code from the book, sample data, additional notes from the authors, and 25 bonus macros. To download the code files, visit this book’s web page at http://www.quepublishing.com or http://www.mrexcel.com/getcode2016.html.

Next Steps

Chapter 1 introduces the editing tools of the Visual Basic environment and shows why using the macro recorder is not an effective way to write VBA macro code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset