Excel 2016 Power Programming with VBA

Michael Alexander

ISBN: 9788126560608

764 pages

INR 999

Description

This book is indispensable for Excel intermediate users, power users, and would-be power users. Fully updated for the new release, this latest edition provides comprehensive, soup-to-nuts coverage, delivering over 900 pages of Excel tips, tricks and techniques readers won't find anywhere else. Thoroughly updated to cover the Excel interface, file formats, enhanced interactivity with other Office applications, and upgraded collaboration features. This power-user's guide is packed with procedures, tips, and ideas for expanding Excel's capabilities with Visual Basic for Applications. Includes templates and worksheets from the book that are downloadable on the website.

Introduction

 

Part I: Introduction to Excel VBA

Chapter 1: Essentials of Spreadsheet Application Development

  • What Is a Spreadsheet Application?
  • Steps for Application Development
  • Determining User Needs
  • Planning an Application That Meets User Needs
  • Determining the Most Appropriate User Interface
  • Customizing the Ribbon
  • Customizing shortcut menus
  • Creating shortcut keys
  • Creating custom dialog boxes
  • Using ActiveX controls on a worksheet
  • Executing the development effort
  • Concerning Yourself with the End User
  • Testing the application
  • Making the application bulletproof
  • Making the application aesthetically appealing and intuitive
  • Creating a user Help system
  • Documenting the development effort
  • Distributing the application to the user
  • Updating the application when necessary
  • Other Development Issues
  • The user's installed version of Excel
  • Language issues
  • System speed
  • Video modes

 

Chapter 2: Introducing Visual Basic for Applications

  • Getting a Head Start with the Macro Recorder
  • Creating your first macro
  • Comparing absolute and relative macro recording
  • Other macro recording concepts
  • Working with the Visual Basic Editor
  • Understanding VBE components
  • Working with the Project window
  • Working with a Code window
  • Customizing the VBA environment
  • The Editor Format tab
  • The General tab
  • The Docking tab
  • VBA Fundamentals
  • Understanding objects
  • Understanding collections
  • Understanding properties
  • Deep Dive: Working with Range Objects
  • Finding the properties of the Range object
  • The Range property
  • The Cells property
  • The Offset property
  • Essential Concepts to Remember
  • Don't Panic--You Are Not Alone
  • Read the rest of the book
  • Let Excel help write your macro
  • Use the Help system
  • Use the Object Browser
  • Pilfer code from the Internet
  • Leverage user forums
  • Visit expert blogs
  • Mine YouTube for video training
  • Learn from the Microsoft Office Dev Center
  • Dissect the other Excel files in your organization
  • Ask your local Excel genius

 

Chapter 3: VBA Programming Fundamentals

  • VBA Language Elements: An Overview
  • Comments
  • Variables, Data Types and Constants
  • Defining data types
  • Declaring variables
  • Scoping variables
  • Working with constants
  • Working with strings
  • Working with dates
  • Assignment Statements
  • Arrays
  • Declaring arrays
  • Declaring multidimensional arrays
  • Declaring dynamic arrays
  • Object Variables
  • User-Defined Data Types
  • Built-In Functions
  • Manipulating Objects and Collections
  • With-End With constructs
  • For Each-Next constructs
  • Controlling Code Execution
  • GoTo statements
  • If-Then constructs
  • Select Case constructs
  • Looping blocks of instructions

 

Chapter 4: Working with VBA Sub Procedures

  • About Procedures
  • Declaring a Sub procedure
  • Scoping a procedure
  • Executing Sub Procedures
  • Executing a procedure with the Run Sub / User Form command
  • Executing a procedure from the Macro dialog box
  • Executing a procedure with a Ctrl+shortcut key combination
  • Executing a procedure from the Ribbon
  • Executing a procedure from a customized shortcut menu
  • Executing a procedure from another procedure
  • Executing a procedure by clicking an object
  • Executing a procedure when an event occurs
  • Executing a procedure from the Immediate window
  • Passing Arguments to Procedures
  • Error-Handling Techniques
  • Trapping errors
  • Error-handling examples
  • A Realistic Example That Uses Sub Procedures
  • The goal
  • Project requirements
  • What you know
  • The approach
  • Some preliminary recording
  • Initial setup
  • Code writing
  • Writing the Sort procedure
  • More testing
  • Fixing the problems
  • Utility availability
  • Evaluating the project

 

Chapter 5: Creating Function Procedures

  • Sub Procedures versus Function Procedures
  • Why Create Custom Functions?
  • An Introductory Function Example
  • Using the function in a worksheet
  • Using the function in a VBA procedure
  • Analyzing the custom function
  • Function Procedures
  • A function's scope
  • Executing function procedures
  • Function Arguments
  • Function Examples
  • Functions with no argument
  • A function with one argument
  • A function with two arguments
  • A function with an array argument
  • A function with optional arguments
  • A function that returns a VBA array
  • A function that returns an error value
  • A function with an indefinite number of arguments
  • Emulating Excel's SUM Function
  • Extended Date Functions
  • Debugging Functions
  • Dealing with the Insert Function Dialog Box
  • Using the Macro Options method
  • Specifying a function category
  • Adding a function description manually
  • Using Add-Ins to Store Custom Functions
  • Using the Windows API
  • Windows API examples
  • Determining the Windows directory
  • Detecting the Shift key
  • Learning more about API functions

 

Chapter 6: Understanding Excel's Events

  • What You Should Know about Events
  • Understanding event sequences
  • Where to put event-handler procedures
  • Disabling events
  • Entering event-handler code
  • Event-handler procedures that use arguments
  • Getting Acquainted with Workbook-Level Events
  • The Open event
  • The Activate event
  • The Sheet Activate event
  • The New Sheet event
  • The Before Save event
  • The Deactivate event
  • The Before Print event
  • The Before Close event
  • Examining Worksheet Events
  • The Change event
  • Monitoring a specific range for changes
  • The Selection Change event
  • The Before Double Click event
  • The Before Right Click event  
  • Monitoring with Application Events
  • Enabling Application-level events  
  • Determining when a workbook is opened
  • Monitoring Application-level events
  • Accessing Events Not Associated with an Object
  • The On Time event
  • The On Key event

 

Chapter 7: VBA Programming Examples and Techniques

  • Learning by Example
  • Working with Ranges  
  • Copying a range
  • Moving a range  
  • Copying a variably sized range
  • Selecting or otherwise identifying various types of ranges
  • Resizing a range
  • Prompting for a cell value
  • Entering a value in the next empty cell
  • Pausing a macro to get a user-selected range
  • Counting selected cells
  • Determining the type of selected range
  • Looping through a selected range efficiently
  • Deleting all empty rows
  • Duplicating rows a variable number of times
  • Determining whether a range is contained in another range
  • Determining a cell's data type
  • Reading and writing ranges
  • A better way to write to a range
  • Transferring one-dimensional arrays
  • Transferring a range to a variant array
  • Selecting cells by value
  • Copying a noncontiguous range
  • Working with Workbooks and Sheets
  • Saving all workbooks
  • Saving and closing all workbooks
  • Hiding all but the selection
  • Creating a hyperlink table of contents
  • Synchronizing worksheets
  • VBA Techniques
  • Toggling a Boolean property
  • Displaying the date and time
  • Displaying friendly time
  • Getting a list of fonts
  • Sorting an array
  • Processing a series of files
  • Some Useful Functions for Use in Your Code
  • The File Exists function
  • The File name Only function
  • The Path Exists function
  • The Range Name Exists function
  • The Sheet Exists function
  • The Work book Is Open function
  • Retrieving a value from a closed workbook
  • Some Useful Worksheet Functions
  • Returning cell formatting information
  • A talking worksheet
  • Displaying the date when a file was saved or printed
  • Understanding object parents
  • Counting cells between two values
  • Determining the last nonempty cell in a column or row
  • Does a string match a pattern?
  • Extracting the nth element from a string
  • Spelling out a number
  • A multifunctional function
  • The SHEETOFFSET function
  • Returning the maximum value across all worksheets
  • Returning an array of non-duplicated random integers
  • Randomizing a range
  • Sorting a range
  • Windows API Calls
  • Understanding API Declarations
  • Determining file associations
  • Determining default printer information
  • Determining video display information
  • Reading from and writing to the Registry

 

Part II: Advanced VBA Techniques

Chapter 8: Working with Pivot Tables

  • An Introductory Pivot Table Example
  • Creating a pivot table
  • Examining the recorded code for the pivot table
  • Cleaning up the recorded pivot table code
  • Creating a More Complex Pivot Table
  • The code that created the pivot table
  • How the more complex pivot table works
  • Creating Multiple Pivot Tables
  • Creating a Reverse Pivot Table

 

Chapter 9: Working with Charts

  • Getting the Inside Scoop on Charts
  • Chart locations
  • The macro recorder and charts
  • The Chart object model
  • Creating an Embedded Chart
  • Creating a Chart on a Chart Sheet
  • Modifying Charts
  • Using VBA to Activate a Chart
  • Moving a Chart
  • Using VBA to Deactivate a Chart
  • Determining Whether a Chart Is Activated
  • Deleting from the Chart Objects or Charts Collection
  • Looping through All Charts
  • Sizing and Aligning Chart Objects
  • Creating Lots of Charts
  • Exporting a Chart
  • Exporting all graphics
  • Changing the Data Used in a Chart
  • Changing chart data based on the active cell
  • Using VBA to determine the ranges used in a chart
  • Using VBA to Display Arbitrary Data Labels on a Chart
  • Displaying a Chart in a User Form
  • Understanding Chart Events
  • An example of using Chart events
  • Enabling events for an embedded chart
  • Example: Using Chart events with an embedded chart
  • Discovering VBA Charting Tricks
  • Printing embedded charts on a full page
  • Creating unlinked charts
  • Displaying text with the Mouse Over event
  • Scrolling a chart
  • Working with Sparkline Charts

 

Chapter 10: Interacting with Other Applications

  • Understanding Microsoft Office Automation
  • Understanding the concept of binding
  • A simple automation example
  • Automating Access from Excel
  • Running an Access Query from Excel
  • Running an Access Macro from Excel
  • Automating Word from Excel
  • Sending Excel data to a Word document
  • Simulating mail merge with a Word document
  • Automating PowerPoint from Excel
  • Sending Excel data to a PowerPoint presentation
  • Sending all Excel charts to a PowerPoint presentation
  • Convert a workbook into a PowerPoint presentation
  • Automating Outlook from Excel
  • Mailing the Active Workbook as an Attachment
  • Mailing a Specific Range as an Attachment
  • Mailing a Single Sheet as an Attachment
  • Mailing All Email Addresses in Your Contact List
  • Starting Other Applications from Excel
  • Using the VBA Shell function
  • Using the Windows Shell Execute API function
  • Using App Activate
  • Running Control Panel dialog boxes

 

Chapter 11: Working with External Data and Files

  • Working with External Data Connections
  • Manually creating a connection
  • Manually editing data connections
  • Using VBA to create dynamic connections
  • Iterating through all connections in a workbook
  • Using ADO and VBA to Pull External Data
  • The connection string
  • Declaring a Record set
  • Referencing the ADO object library
  • Putting it all together in code
  • Using ADO with the active workbook
  • Working with Text Files
  • Opening a text file
  • Reading a text file
  • Writing a text file
  • Getting a file number
  • Determining or setting the file position
  • Statements for reading and writing
  • Text File Manipulation Examples
  • Importing data in a text file
  • Exporting a range to a text file
  • Importing a text file to a range
  • Logging Excel usage
  • Filtering a text file
  • Performing Common File Operations
  • Using VBA file-related statements
  • Using the File System Object object
  • Zipping and Unzipping Files
  • Zipping files
  • Unzipping a file

 

Part III: Working with User Forms

Chapter 12: Leveraging Custom Dialog Boxes

  • Before You Create That User Form
  • Using an Input Box
  • The VBA Input Box function
  • The Application.InputBox method
  • The VBA Msg Box Function
  • The Excel Get Open Filename Method
  • The Excel Get Save As Filename Method
  • Prompting for a Directory
  • Displaying Excel's Built-In Dialog Boxes
  • Displaying a Data Form
  • Making the data form accessible
  • Displaying a data form by using VBA

 

Chapter 13: Introducing User Forms

  • How Excel Handles Custom Dialog Boxes
  • Inserting a New User Form
  • Adding Controls to a User Form
  • Toolbox Controls
  • Checkbox
  • Combo Box
  • Command Button
  • Frame
  • Image
  • Label
  • List Box
  • Multipage
  • Option Button
  • Ref Edit
  • Scroll Bar
  • Spin Button
  • Tab Strip
  • Text Box
  • Toggle Button
  • Adjusting User Form Controls
  • Adjusting a Control's Properties
  • Using the Properties window
  • Common properties
  • Accommodating keyboard users
  • Displaying a User Form
  • Adjusting the display position
  • Displaying a modeless User Form
  • Displaying a User Form based on a variable
  • Loading a User Form
  • About event-handler procedures
  • Closing a User Form
  • Creating a User Form: An Example
  • Creating the User Form
  • Writing code to display the dialog box
  • Testing the dialog box
  • Adding event-handler procedures
  • The finished dialog box
  • Understanding User Form Events
  • Learning about events
  • User Form events
  • Spin Button events
  • Pairing a Spin Button with a Textbox
  • Referencing User Form Controls
  • Customizing the Toolbox
  • Adding new pages to the Toolbox
  • Customizing or combining controls
  • Adding new ActiveX controls
  • Creating User Form Templates
  • A User Form Checklist

 

Chapter 14: User Form Examples

  • Creating a User Form "Menu"
  • Using Command Buttons in a User Form
  • Using a List Box in a User Form
  • Selecting Ranges from a User Form
  • Creating a Splash Screen
  • Disabling a User Form's Close Button
  • Changing a User Form's Size
  • Zooming and Scrolling a Sheet from a User Form
  • List Box Techniques
  • Adding items to a List Box control
  • Determining the selected item in a List Box
  • Determining multiple selections in a List Box
  • Multiple lists in a single List Box
  • List Box item transfer
  • Moving items in a List Box
  • Working with multicolumn List Box controls
  • Using a List Box to select worksheet rows
  • Using a List Box to activate a sheet
  • Filtering a List Box from a Text Box
  • Using the Multi Page Control in a User Form
  • Using an External Control
  • Animating a Label

 

Chapter 15: Advanced User Form Techniques

  • A Modeless Dialog Box
  • Displaying a Progress Indicator
  • Creating a stand-alone progress indicator
  • Showing a progress indicator that's integrated into a User Form
  • Creating a non-graphical progress indicator
  • Creating Wizards
  • Setting up the Multi Page control for the wizard
  • Adding the buttons to the wizard's User Form
  • Programming the wizard's buttons
  • Programming dependencies in a wizard
  • Performing the task with the wizard
  • Emulating the Msg Box Function
  • Msg Box emulation: My Msg Box code
  • How the My Msg Box function works
  • Using the My Msg Box function
  • A User Form with Movable Controls
  • A User Form with No Title Bar
  • Simulating a Toolbar with a User Form
  • Emulating a Task Pane with a User Form
  • A Resizable User Form
  • Handling Multiple User Form Controls with One Event Handler
  • Selecting a Color in a User Form
  • Displaying a Chart in a User Form
  • Saving a chart as a GIF file
  • Changing the Image control's Picture property
  • Making a User Form Semitransparent
  • A Puzzle on a User Form
  • Video Poker on a User Form

 

Part IV: Developing Excel Applications

Chapter 16: Creating and Using Add-Ins

  • What Is an Add-In?
  • Comparing an add-in with a standard workbook
  • Why create add-ins?
  • Understanding Excel's Add-In Manager
  • Creating an Add-in
  • An Add-In Example
  • Adding descriptive information for the example add-in
  • Creating an add-in
  • Installing an add-in
  • Testing the add-in
  • Distributing an add-in
  • Modifying an add-in
  • Comparing XLAM and XLSM Files
  • XLAM file VBA collection membership
  • Visibility of XLSM and XLAM files  
  • Worksheets and chart sheets in XLSM and XLAM files
  • Accessing VBA procedures in an add-in
  • Manipulating Add-Ins with VBA
  • Adding an item to the Add Ins collection
  • Removing an item from the Add Ins collection  
  • Add In object properties
  • Accessing an add-in as a workbook
  • Add In object events  
  • Optimizing the Performance of Add-Ins
  • Special Problems with Add-Ins  
  • Ensuring that an add-in is installed  
  • Referencing other files from an add-in  
  • Detecting the proper Excel version for your add-in

 

Chapter 17: Working with the Ribbon

  • Ribbon Basics
  • Customizing the Ribbon
  • Adding a button to the Ribbon
  • Adding a button to the Quick Access Toolbar
  • Understanding the limitations of Ribbon customization
  • Creating a Custom Ribbon
  • Adding a button to an existing tab
  • Adding a check box to an existing tab
  • Ribbon controls demo
  • A dynamic Menu control example
  • More on Ribbon customization
  • Using VBA with the Ribbon
  • Accessing a Ribbon control
  • Working with the Ribbon
  • Activating a tab
  • Creating an Old-Style Toolbar
  • Limitations of old-style toolbars in Excel 2007 and later
  • Code to create a toolbar

 

Chapter 18: Working with Shortcut Menus

  • Command Bar Overview
  • Command Bar types
  • Listing shortcut menus
  • Referring to Command Bars
  • Referring to controls in a Command Bar
  • Properties of Command Bar controls
  • Displaying all shortcut menu items
  • Using VBA to Customize Shortcut Menus
  • Shortcut menu and the single-document interface
  • Resetting a shortcut menu
  • Disabling a shortcut menu
  • Disabling shortcut menu items
  • Adding a new item to the Cell shortcut menu
  • Adding a submenu to a shortcut menu
  • Limiting a shortcut menu to a single workbook
  • Shortcut Menus and Events
  • Adding and deleting menus automatically
  • Disabling or hiding shortcut menu items
  • Creating a context-sensitive shortcut menu

 

Chapter 19: Providing Help for Your Applications

  • Help for Your Excel Applications
  • Help Systems That Use Excel Components
  • Using cell comments for help
  • Using a text box for help
  • Using a worksheet to display help text
  • Displaying help in a User Form
  • Displaying Help in a Web Browser
  • Using HTML files
  • Using an MHTML file
  • Using the HTML Help System
  • Using the Help method to display HTML Help
  • Associating a help file with your application
  • Associating a help topic with a VBA function

 

Chapter 20: Leveraging Class Modules

  • What Is a Class Module?
  • Built-in class modules
  • Custom class modules
  • Creating a Num Lock Class
  • Inserting a class module
  • Adding VBA code to the class module
  • Using the C Num Lock class
  • Coding Properties, Methods and Events
  • Programming properties of objects
  • Programming methods for objects
  • Class module events
  • Exposing a Query Table Event
  • Creating a Class to Hold Classes
  • Creating the C Sal