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

Mike Van Niekerk

  1. 362 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

VBA Automation for Excel 2019 Cookbook

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

Mike Van Niekerk

Detalles del libro
Vista previa del libro
Índice
Citas

Información del libro

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.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es VBA Automation for Excel 2019 Cookbook un PDF/ePUB en línea?
Sí, puedes acceder a VBA Automation for Excel 2019 Cookbook de Mike Van Niekerk en formato PDF o ePUB, así como a otros libros populares de Ciencia de la computación y Aplicaciones de escritorio. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2020
ISBN
9781789616330

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...

Índice