VBA Automation for Excel 2019 Cookbook
eBook - ePub

VBA Automation for Excel 2019 Cookbook

Solutions to automate routine tasks and increase productivity with Excel and other MS Office applications

  1. 362 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

VBA Automation for Excel 2019 Cookbook

Solutions to automate routine tasks and increase productivity with Excel and other MS Office applications

About this book

A comprehensive guide to gaining a 360-degree overview of the VBA programming language and learning how to build your own programs for automating routine tasks

Key Features

  • Extend the capabilities of Excel and other Office applications with the help of Microsoft VBA
  • Take your Excel programming skills to the next level by creating custom applications with dialogue boxes and the range object
  • Automate repetitive and monotonous office work with VBA Excel programming

Book Description

Visual Basic for Applications (VBA) is a programming language developed by Microsoft to automate tasks in MS Office applications. This book will help you to focus on the essential aspects of your role by automating mundane tasks in Excel and other Office applications. With comprehensive coverage of VBA delivered in the form of practice problems and bite-sized recipes, this book will help you to hit the ground running.

Unlike most books that assume prior programming experience, this book starts with the fundamentals and gradually progresses to solving bigger problems.

You'll start by becoming familiar with VBA so that you can start recording macros right away. With this foundation in place, you'll advance to using the full capabilities of the language as you apply loops, functions, and custom dialog boxes to design your own automation programs. You'll also get to grips with embedded macros and other advanced tools to enhance productivity and explore topics relating to app performance and security. Throughout this VBA book, you'll cover multiple practice projects in Excel, Word, and PowerPoint while exploring tips and best practices to hone your skills.

By the end of this book, you'll have developed the skills you need to use VBA to create your own programs that control MS Office applications.

What you will learn

  • Understand the VBA programming language's role in the context of the MS Office suite
  • Discover various aspects of VBA programming such as its terminology, syntax, procedures, functions, and forms
  • Investigate the elements, features, and characteristics of the VBA Editor to write and edit custom scripts
  • Automate Excel sheets with the help of ranges
  • Explore error handling and debugging techniques to catch bugs in your programs
  • Create and use custom dialog boxes to collect data from users
  • Customize and extend Office apps such as Excel, PowerPoint, and Word

Who this book is for

This book is for experienced Excel users, business analysts, finance professionals, and business users looking to boost their productivity by learning VBA programming to automate repetitive, tedious, or complex tasks. No prior programming experience is required to get started with this book.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weโ€™ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere โ€” even offline. Perfect for commutes or when youโ€™re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access VBA Automation for Excel 2019 Cookbook by Mike Van Niekerk in PDF and/or ePUB format, as well as other popular books in Computer Science & Desktop Applications. We have over one million books available in our catalogue for you to explore.

Information

Chapter 1: Getting Started with VBA

The recipes in this chapter will help you familiarize yourself with VBA in general, introduce you to the VBA working environment, and also help you edit and save your first working VBA subroutine. In the process, you will learn how to set up the development environment and how to edit your VBA coding.
In this chapter, we will cover the following recipes:
  • Investigating VBA code
  • Recording a macro
  • Testing the macro
  • Using the VBA Editor
  • Editing the code by changing cell references
  • Saving the file with an embedded macro
  • Using the Trust Center for macro security
  • Creating a customized ribbon
By the end of this chapter, you will be able to identify the need and use for a macro, record a macro, edit VBA code, and save the macro in an Excel Workbook.

Technical requirements

This cookbook was written and designed to be used with MS Office 2019 and MS Office 365, installed on either Windows 8, 8.1, or 10.
In the case of MS Word, MS Excel, and MS PowerPoint, the Developer ribbon can be activated, although this is not a prerequisite. In all the applications, on the View ribbon | Macros group, there are icons for viewing and recording macros.
Demonstration files can be downloaded from https://github.com/PacktPublishing/VBA-Automation-for-Excel-2019-Cookbook.
Please visit the following link to check out the CiA videos: https://bit.ly/3jQRvVk.

Investigating VBA code

In this recipe, we will inspect a short VBA subroutine. Like all programming languages, VBA has a specific syntax, and the best way to understand the principles is to see what the coding looks like.
What we're going to see here will lay the foundation for the other recipes in this book, so pay close attention.

Getting ready

In order to investigate and edit VBA code in Excel, or any of the other Office applications, we first need to activate the Developer toolbar. Here are the steps:
  1. Open MS Excel and select Blank workbook from the opening screen.
  2. Open the 01_VBA_Code.xlsm sample file. Click on [Enable Content] on the SECURITY WARNING ribbon.
  3. If the Developer ribbon is not visible, activate the Backstage View by clicking on File, which will display the following screen:
    Figure 1.1 โ€“ The Backstage View
  4. From the category list on the left, select the last option, Options. The Excel Options dialog box appears:
    Figure 1.2 โ€“ The Excel Options dialog box
    Figure 1.2 โ€“ The Excel Options dialog box
  5. From the categories on the left, select Customize Ribbon.
  6. To the far right, under the Main Tabs heading, look for the Developer option. Select the checkbox.
  7. Click on OK to accept the change. The dialog box will close, and Excel will now display the Developer tab.

How to do itโ€ฆ

With the Developer tab activated, we will now proceed with the steps for this recipe:
  1. With 01_VBA_Code.xlsm open, click on the Developer tab:
    Figure 1.3 โ€“ The Developer tab
    Figure 1.3 โ€“ The Developer tab
  2. In the Code group (the first group on the left of the ribbon), select the Macros icon. The Macro dialog box opens:
    Figure 1.4 โ€“ The Macro dialog box
    Figure 1.4 โ€“ The Macro dialog box
  3. The VBA code we want to investigate is contained in the only macro: Area_Bold. Click on the Edit button. The Microsoft Visual Basic for Applications window will open. Maximize the window, if necessary:
    Figure 1.5 โ€“ The Microsoft Visual Basic for Applications editor window
    Figure 1.5 โ€“ The Microsoft Visual Basic for Applications editor window
  4. In the code window (the large area on the right), a short VBA subroutine is displayed.

How it worksโ€ฆ

The subroutine in the VBA Editor looks like this:
Figure 1.6 โ€“ The subroutine in the VBA Editor
Figure 1.6 โ€“ The subroutine in the VBA Editor
Let's try to understand this subroutine. Any and all subroutines in VBA start with the Sub keyword, followed by the name of the subroutine (macro), and end with two brackets.
A single apostrophe allows you to enter a note. Comments can be added anywhere in a subroutine and will be displayed in green text, as long as it is on its own line or after a line of code (that is, it cannot be before a line of code as it would obviously comment out the code too). Indented lines wi...

Table of contents

  1. VBA Automation for Excel 2019 Cookbook
  2. Why subscribe?
  3. Preface
  4. Chapter 1: Getting Started with VBA
  5. Chapter 2: Working with the VBA Editor
  6. Chapter 3: The VBA Object Model
  7. Chapter 4: Working with Procedures
  8. Chapter 5: Next Level Recording
  9. Chapter 6: VBA Language Elements
  10. Chapter 7: Working with Ranges
  11. Chapter 8: Using Functions
  12. Chapter 9: Implementing Program Flow
  13. Chapter 10: Implementing Automation
  14. Chapter 11: Handling Errors
  15. Chapter 12: Debugging
  16. Chapter 13: Creating and Modifying Dialog Boxes
  17. Chapter 14: Creating UserForms
  18. Chapter 15: UserForm Controls
  19. Chapter 16: Creating Custom Functions
  20. Chapter 17: Creating Word Documents with Excel VBA
  21. Chapter 18: Working with PowerPoint in Excel VBA
  22. Other Books You May Enjoy