ebook img

Excel 2019 Power Programming with VBA PDF

756 Pages·2019·15.64 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Excel 2019 Power Programming with VBA

Excel® 2019 Power Programming with VBA Excel® 2019 Power Programming with VBA Michael Alexander Dick Kusleika Previously by John Walkenbach Excel® 2019 Power Programming with VBA Published by John Wiley & Sons, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2019 by John Wiley & Sons, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-1-119-51492-3 ISBN: 978-1-119-51494-7 (ebk) ISBN: 978-1-119-51491-6 (ebk) Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or website may provide or recommendations it may make. Further, readers should be aware that Internet websites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com. Library of Congress Control Number: 2019936928 Trademarks: Wiley and the Wiley logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/ or its affiliates, in the United States and other countries, and may not be used without written permission. Microsoft and Excel are registered trademarks of Microsoft Corporation. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book. About the Authors Michael Alexander is a Microsoft Certified Application Developer (MCAD) and author of sev- eral books on advanced business analysis with Microsoft Access and Microsoft Excel. He has more than 20 years of experience consulting and developing Microsoft Office solutions. Mike has been named a Microsoft MVP for his ongoing contributions to the Excel community. You can find Mike at www.datapigtechnologies.com. Dick Kusleika is a 12-time Microsoft Excel MVP and has been working with Microsoft Office for more than 20 years. Dick develops Access- and Excel-based solutions for his clients and has conducted training seminars on Office products in the United States and Australia. Dick also writes a popular Excel-related blog at www.dailydoseofexcel.com. v About the Technical Editors Doug Holland is an Architect Evangelist at Microsoft Corporation, working with partners to drive digital transformation through technologies such as the Microsoft Cloud, Office 365, and HoloLens. He holds a master’s degree in software engineering from Oxford University and lives in Northern California with his wife and five children. Guy Hart-Davis is the author of an improbable number of computer books on a bizarre range of topics. If you had been wondering who was responsible for the Word 2000 Developer’s Hand- book, AppleScript: A Beginner’s Guide, iMac Portable Genius, or Samsung Galaxy S8 Maniac’s Guide, you need wonder no more. vii Credits Associate Publisher Copy Editor Jim Minatel Kim Wimpsett Senior Editorial Assistant Proofreader Devon Lewis Nancy Bell Editorial Manager Indexer Pete Gaughan Johnna VanHoose Dinse Production Manager Cover Designer Katie Wisor Wiley Project Editor Cover Image Gary Schwartz © Rost-9D/Getty Images Production Editor Barath Kumar Rajasekaran Technical Editors Doug Holland Guy Hart-Davis ix Acknowledgments Our deepest thanks to the professionals at John Wiley & Sons for all the hours of work put into bringing this book to life. Thanks also to Doug Holland and Guy Hart-Davis for suggesting numerous improvements to the examples and text in this book. A special thank-you goes out to our families for putting up with all the time spent locked away on this project. Finally, we’d like to thank John Walkenbach for his many years of work on the previous editions of this book. His efforts in curating Excel knowledge have been instrumental, not only in helping millions of Excel users to achieve their learning goals but also in inspiring countless Excel MVPs to share their expertise with the Excel community. xi Contents at a Glance Introduction ..........................................................................................................xxxiii Part I: Introduction to Excel VBA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Chapter 1: Essentials of Spreadsheet Application Development ..........................................3 Chapter 2: Introducing Visual Basic for Applications .......................................................19 Chapter 3: VBA Programming Fundamentals ...................................................................61 Chapter 4: Working with VBA Sub Procedures ...............................................................105 Chapter 5: Creating Function Procedures ......................................................................143 Chapter 6: Understanding Excel’s Events .......................................................................183 Chapter 7: VBA Programming Examples and Techniques .................................................217 Part II: Advanced VBA Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 Chapter 8: Working with Pivot Tables ...........................................................................289 Chapter 9: Working with Charts ...................................................................................305 Chapter 10: Interacting with Other Applications ...........................................................351 Chapter 11: Working with External Data and Files .........................................................377 Part III: Working with UserForms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417 Chapter 12: Leveraging Custom Dialog Boxes ................................................................419 Chapter 13: Introducing UserForms ..............................................................................441 Chapter 14: Looking at UserForm Examples ...................................................................479 Chapter 15: Implementing Advanced UserForm Techniques ............................................519 Part IV: Developing Excel Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . 567 Chapter 16: Creating and Using Add-Ins .......................................................................569 Chapter 17: Working with the Ribbon ...........................................................................599 Chapter 18: Working with Shortcut Menus ....................................................................637 Chapter 19: Providing Help for Your Applications ..........................................................659 Chapter 20: Leveraging Class Modules ..........................................................................679 Chapter 21: Understanding Compatibility Issues ...........................................................699 Part V: Appendix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 713 Appendix: VBA Statements and Functions Reference .....................................................715 Index ........................................................................................................................725 xiii Contents Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxxiii Part I: Introduction to Excel VBA 1 Chapter 1: Essentials of Spreadsheet Application Development. . . . . . . . . . . . . . . . . . . . .3 What Is a Spreadsheet Application? ........................................................................3 Steps for Application Development .........................................................................4 Determining User Needs ........................................................................................5 Planning an Application That Meets User Needs ......................................................6 Determining the Most Appropriate User Interface ....................................................7 Customizing the Ribbon ................................................................................8 Customizing shortcut menus .........................................................................8 Creating shortcut keys ..................................................................................9 Creating custom dialog boxes ........................................................................9 Using ActiveX controls on a worksheet .........................................................10 Executing the development effort ................................................................12 Concerning Yourself with the End User ..................................................................12 Testing the application ................................................................................12 Making the application bulletproof ...............................................................13 Making the application aesthetically appealing and intuitive .........................15 Creating a user Help system .........................................................................16 Documenting the development effort ............................................................16 Distributing the application to the user ........................................................16 Updating the application when necessary .....................................................17 Other Development Issues.....................................................................................17 The user’s installed version of Excel ..............................................................17 Language issues ..........................................................................................17 System speed ..............................................................................................18 Video modes ...............................................................................................18 Chapter 2: Introducing Visual Basic for Applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . .19 Getting a Head Start with the Macro Recorder ........................................................19 Creating your first macro .............................................................................20 Examining your macro ........................................................................21 xv

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.