0% found this document useful (0 votes)
4 views

Excel 2007 VBA Programming For Dummies 1st Edition Walkenbach download

Ebook installation

Uploaded by

baudespikane
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Excel 2007 VBA Programming For Dummies 1st Edition Walkenbach download

Ebook installation

Uploaded by

baudespikane
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Excel 2007 VBA Programming For Dummies 1st

Edition Walkenbach download

https://ebookultra.com/download/excel-2007-vba-programming-for-
dummies-1st-edition-walkenbach/

Explore and download more ebooks or textbooks


at ebookultra.com
Here are some recommended products for you. Click the link to
download, or explore more at ebookultra.com

Excel Vba Programming For Dummies 4e 4th Edition


Walkenbach

https://ebookultra.com/download/excel-vba-programming-for-
dummies-4e-4th-edition-walkenbach/

Excel 2007 For Dummies Quick Reference John Walkenbach

https://ebookultra.com/download/excel-2007-for-dummies-quick-
reference-john-walkenbach/

Access 2007 VBA Programming For Dummies 1st Edition Joseph


C. Stockman

https://ebookultra.com/download/access-2007-vba-programming-for-
dummies-1st-edition-joseph-c-stockman/

Excel 2007 For Dummies 1st Edition Greg Phd Harvey

https://ebookultra.com/download/excel-2007-for-dummies-1st-edition-
greg-phd-harvey/
Excel Programming with VBA Starter 1st Edition Robert
Martin

https://ebookultra.com/download/excel-programming-with-vba-
starter-1st-edition-robert-martin/

Excel 2007 Workbook for Dummies 2nd edition Edition Greg


Harvey

https://ebookultra.com/download/excel-2007-workbook-for-dummies-2nd-
edition-edition-greg-harvey/

Excel 2007 Data Analysis For Dummies 1st Edition Stephen


L. Nelson

https://ebookultra.com/download/excel-2007-data-analysis-for-
dummies-1st-edition-stephen-l-nelson/

Excel 2007 VBA Programmer s Reference Programmer to


Programmer 1st Edition John Green

https://ebookultra.com/download/excel-2007-vba-programmer-s-reference-
programmer-to-programmer-1st-edition-john-green/

Excel 2010 Bible 1st Edition John Walkenbach

https://ebookultra.com/download/excel-2010-bible-1st-edition-john-
walkenbach/
Excel 2007 VBA Programming For Dummies 1st Edition
Walkenbach Digital Instant Download
Author(s): Walkenbach, John
ISBN(s): 9780470046746, 0470046740
Edition: 1
File Details: PDF, 9.89 MB
Year: 2007
Language: english
www.sharexxx.net - free books & magazines

TEAM LinG
®
Excel 2007 VBA
Programming
FOR

DUMmIES

by John Walkenbach

Revised by Jan Karel Pieterse

TEAM LinG
Excel® 2007 VBA Programming For Dummies®
Published by
Wiley Publishing, Inc.
111 River Street
Hoboken, NJ 07030-5774
www.wiley.com
Copyright © 2007 by Wiley Publishing, Inc., Indianapolis, Indiana
Published by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
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 permit-
ted 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 Legal Department, Wiley Publishing,
Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at
http://www.wiley.com/go/permissions.
Trademarks: Wiley, the Wiley Publishing logo, For Dummies, the Dummies Man logo, A Reference for the
Rest of Us!, The Dummies Way, Dummies Daily, The Fun and Easy Way, Dummies.com, and related trade
dress 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 reg-
istered trademarks of Microsoft Corporation in the United States and/or other countries. All other trade-
marks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any
product or vendor mentioned in this book.

LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REP-
RESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CON-
TENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT
LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CRE-
ATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CON-
TAINED 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 WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FUR-
THER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFOR-
MATION 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 U.S. at 800-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002.
For technical support, please visit www.wiley.com/techsupport.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may
not be available in electronic books.
Library of Congress Control Number: 2006939593
ISBN: 978-0-470-04674-6
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1

TEAM LinG
About the Author
John Walkenbach is the author of more than 50 spreadsheet books and lives
in southern Arizona. Visit his Web site at http://j-walk.com.

Dedication
“This book is dedicated to Jim Kloss and Esther Golton — my two favorite
people in Matanuska-Susitna county. By putting their names in this book, I’m
ensured of at least one sale in Alaska.”

Author’s Acknowledgments
Thanks to all of the talented people at Wiley Publishing for making it so easy
to write these books. And special thanks to Jan Karel Pieterse for his assis-
tance with this edition.

TEAM LinG
Publisher’s Acknowledgments
We’re proud of this book; please send us your comments through our online registration form
located at www.dummies.com/register/.
Some of the people who helped bring this book to market include the following:

Acquisitions, Editorial, and Composition Services


Media Development Project Coordinator: Jennifer Theriot
Project Editor: Beth Taylor Layout and Graphics: Carl Byers, Stephanie D.
Executive Editor: Greg Croy Jumper, Barbara Moore,
Copy Editor: Beth Taylor Julie Trippetti

Technical Editor: Allen Wyatt Proofreaders: Laura Albert, John Greenough,


Techbooks
Editorial Manager: Jodi Jensen
Indexer: Techbooks
Media Development Coordinator:
Laura Atkinson
Media Project Supervisor: Laura Moss
Media Development Manager:
Laura VanWinkle
Media Development Associate Producer:
Richard Graves
Editorial Assistant: Amanda Foxworth
Sr. Editorial Assistant: Cherie Case
Cartoons: Rich Tennant
(www.the5thwave.com)

Publishing and Editorial for Technology Dummies


Richard Swadley, Vice President and Executive Group Publisher
Andy Cummings, Vice President and Publisher
Mary Bednarek, Executive Acquisitions Director
Mary C. Corder, Editorial Director
Publishing for Consumer Dummies
Diane Graves Steele, Vice President and Publisher
Joyce Pepple, Acquisitions Director
Composition Services
Gerry Fahey, Vice President of Production Services
Debbie Stailey, Director of Composition Services

TEAM LinG
Contents at a Glance
Introduction .................................................................1
Part I: Introducing VBA ................................................9
Chapter 1: What Is VBA?..................................................................................................11
Chapter 2: Jumping Right In............................................................................................21

Part II: How VBA Works with Excel..............................33


Chapter 3: Working In the Visual Basic Editor..............................................................35
Chapter 4: Introducing the Excel Object Model ...........................................................53
Chapter 5: VBA Sub and Function Procedures .............................................................67
Chapter 6: Using the Excel Macro Recorder .................................................................79

Part III: Programming Concepts...................................91


Chapter 7: Essential VBA Language Elements ..............................................................93
Chapter 8: Working with Range Objects......................................................................113
Chapter 9: Using VBA and Worksheet Functions .......................................................125
Chapter 10: Controlling Program Flow and Making Decisions .................................139
Chapter 11: Automatic Procedures and Events..........................................................157
Chapter 12: Error-Handling Techniques ......................................................................177
Chapter 13: Bug Extermination Techniques ...............................................................191
Chapter 14: VBA Programming Examples ...................................................................203

Part IV: Communicating with Your Users ....................221


Chapter 15: Simple Dialog Boxes..................................................................................223
Chapter 16: UserForm Basics........................................................................................239
Chapter 17: Using UserForm Controls .........................................................................255
Chapter 18: UserForm Techniques and Tricks ...........................................................275
Chapter 19: Accessing Your Macros Through the User Interface ............................299

Part V: Putting It All Together ...................................315


Chapter 20: Creating Worksheet Functions and Living to Tell about It...................317
Chapter 21: Creating Excel Add-Ins..............................................................................333

TEAM LinG
Part VI: The Part of Tens ...........................................345
Chapter 22: Ten VBA Questions (And Answers) ........................................................347
Chapter 23: (Almost) Ten Excel Resources.................................................................351

Index .......................................................................355

TEAM LinG
Table of Contents
Introduction..................................................................1
Is This the Right Book?....................................................................................1
So You Want to Be a Programmer . . . ............................................................2
Why Bother? .....................................................................................................2
What I Assume about You ...............................................................................3
Obligatory Typographical Conventions Section ..........................................4
Check Your Security Settings..........................................................................4
How This Book Is Organized...........................................................................6
Part I: Introducing VBA ..........................................................................6
Part II: How VBA Works with Excel ......................................................6
Part III: Programming Concepts............................................................6
Part IV: Communicating with Your Users ............................................6
Part V: Putting It All Together...............................................................7
Part VI: The Part of Tens .......................................................................7
Marginal Icons ..................................................................................................7
Get the Sample Files.........................................................................................8
Now What? ........................................................................................................8

Part I: Introducing VBA .................................................9


Chapter 1: What Is VBA? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11
Okay, So What Is VBA?...................................................................................11
What Can You Do with VBA?.........................................................................12
Inserting a bunch of text ....................................................................13
Automating a task you perform frequently.......................................13
Automating repetitive operations ......................................................13
Creating a custom command ..............................................................13
Creating a custom button....................................................................14
Developing new worksheet functions................................................14
Creating complete, macro-driven applications ................................14
Creating custom add-ins for Excel .....................................................14
Advantages and Disadvantages of VBA.......................................................14
VBA advantages....................................................................................15
VBA disadvantages...............................................................................15
VBA in a Nutshell ...........................................................................................16
An Excursion into Versions...........................................................................18

TEAM LinG
viii Excel 2007 VBA Programming For Dummies

Chapter 2: Jumping Right In . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21


First Things First ............................................................................................21
What You’ll Be Doing .....................................................................................22
Taking the First Steps ....................................................................................23
Recording the Macro .....................................................................................23
Testing the Macro ..........................................................................................25
Examining the Macro .....................................................................................25
Modifying the Macro......................................................................................28
Saving Workbooks that Contain Macros .....................................................29
Understanding Macro Security.....................................................................29
More about the NameAndTime Macro ........................................................31

Part II: How VBA Works with Excel ..............................33


Chapter 3: Working In the Visual Basic Editor . . . . . . . . . . . . . . . . . . . .35
What Is the Visual Basic Editor? ..................................................................35
Activating the VBE ...............................................................................35
Understanding VBE components .......................................................36
Working with the Project Explorer...............................................................38
Adding a new VBA module..................................................................39
Removing a VBA module .....................................................................39
Exporting and importing objects .......................................................40
Working with a Code Window.......................................................................40
Minimizing and maximizing windows ................................................40
Creating a module ................................................................................42
Getting VBA code into a module ........................................................42
Entering code directly .........................................................................43
Using the macro recorder ...................................................................45
Copying VBA code................................................................................47
Customizing the VBA Environment .............................................................47
Using the Editor tab .............................................................................48
Using the Editor Format tab................................................................50
Using the General tab ..........................................................................52
Using the Docking tab..........................................................................52

Chapter 4: Introducing the Excel Object Model . . . . . . . . . . . . . . . . . . .53


Excel Is an Object? .........................................................................................54
Climbing the Object Hierarchy.....................................................................54
Wrapping Your Mind around Collections....................................................56
Referring to Objects.......................................................................................56
Navigating through the hierarchy ......................................................57
Simplifying object references..............................................................58
Diving into Object Properties and Methods ...............................................59
Object properties .................................................................................59
Object methods ....................................................................................62
Object events ........................................................................................63
TEAM LinG
Table of Contents ix
Finding Out More ...........................................................................................63
Using VBA’s Help system .....................................................................63
Using the Object Browser....................................................................64

Chapter 5: VBA Sub and Function Procedures . . . . . . . . . . . . . . . . . . . .67


Subs versus Functions...................................................................................67
Looking at Sub procedures .................................................................68
Looking at Function procedures.........................................................68
Naming Subs and Functions................................................................69
Executing Sub procedures ............................................................................69
Executing the Sub procedure directly ...............................................71
Executing the procedure from the Macro dialog box ......................72
Executing a macro by using a shortcut key ......................................72
Executing the procedure from a button or shape ............................74
Executing the procedure from another procedure ..........................76
Executing Function procedures ...................................................................76
Calling the function from a Sub procedure .......................................77
Calling a function from a worksheet formula....................................77

Chapter 6: Using the Excel Macro Recorder . . . . . . . . . . . . . . . . . . . . .79


Is It Live or Is It VBA?.....................................................................................79
Recording Basics............................................................................................80
Preparing to Record.......................................................................................82
Relative or Absolute?.....................................................................................82
Recording in absolute mode ...............................................................82
Recording in relative mode .................................................................83
What Gets Recorded? ....................................................................................85
Recording Options .........................................................................................86
Macro name...........................................................................................87
Shortcut key ..........................................................................................87
Store Macro In.......................................................................................87
Description............................................................................................87
Is This Thing Efficient? ..................................................................................88

Part III: Programming Concepts ...................................91


Chapter 7: Essential VBA Language Elements . . . . . . . . . . . . . . . . . . . .93
Using Comments in Your VBA Code ............................................................93
Using Variables, Constants, and Data Types ..............................................95
Understanding variables .....................................................................95
What are VBA’s data types?.................................................................97
Declaring and scoping variables ........................................................98
Working with constants .....................................................................103
Working with strings ..........................................................................105
Working with dates.............................................................................106

TEAM LinG
x Excel 2007 VBA Programming For Dummies

Using Assignment Statements ....................................................................106


Assignment statement examples......................................................107
About that equal sign.........................................................................107
Other operators..................................................................................108
Working with Arrays ....................................................................................109
Declaring arrays .................................................................................109
Multidimensional arrays....................................................................110
Dynamic arrays...................................................................................111
Using Labels..................................................................................................111

Chapter 8: Working with Range Objects . . . . . . . . . . . . . . . . . . . . . . . .113


A Quick Review.............................................................................................113
Other Ways to Refer to a Range .................................................................114
The Cells property .............................................................................115
The Offset property ...........................................................................116
Referring to entire columns and rows .............................................116
Some Useful Range Object Properties.......................................................117
The Value property ............................................................................117
The Text property ..............................................................................118
The Count property ...........................................................................118
The Column and Row properties .....................................................118
The Address property........................................................................119
The HasFormula property .................................................................119
The Font property ..............................................................................120
The Interior property.........................................................................120
The Formula property .......................................................................121
The NumberFormat property ...........................................................121
Some Useful Range Object Methods..........................................................122
The Select method .............................................................................122
The Copy and Paste methods...........................................................123
The Clear method...............................................................................123
The Delete method.............................................................................124

Chapter 9: Using VBA and Worksheet Functions . . . . . . . . . . . . . . . .125


What Is a Function?......................................................................................125
Using Built-in VBA Functions......................................................................126
VBA function examples......................................................................126
VBA functions that do more than return a value ...........................128
Discovering VBA functions ...............................................................129
Using Worksheet Functions in VBA ...........................................................132
Worksheet function examples ..........................................................133
Entering worksheet functions...........................................................136
More about Using Worksheet Functions ...................................................136
Using Custom Functions .............................................................................137

TEAM LinG
Table of Contents xi
Chapter 10: Controlling Program Flow and Making Decisions . . . . .139
Going with the Flow, Dude ..........................................................................139
The GoTo Statement ....................................................................................140
Decisions, decisions...........................................................................141
The If-Then structure .........................................................................141
The Select Case structure .................................................................146
Knocking Your Code for a Loop .................................................................149
For-Next loops.....................................................................................150
Do-While loop .....................................................................................153
Do-Until loop .......................................................................................154
Looping through a Collection .....................................................................155

Chapter 11: Automatic Procedures and Events . . . . . . . . . . . . . . . . . .157


Preparing for the Big Event.........................................................................157
Are events useful? ..............................................................................159
Programming event-handler procedures ........................................160
Where Does the VBA Code Go? ..................................................................160
Writing an Event-Handler Procedure .........................................................161
Introductory Examples................................................................................163
The Open event for a workbook.......................................................163
The BeforeClose event for a workbook ...........................................165
The BeforeSave event for a workbook.............................................165
Examples of Activation Events ...................................................................166
Activate and deactivate events in a sheet.......................................166
Activate and deactivate events in a workbook...............................167
Workbook activation events .............................................................168
Other Worksheet-Related Events ...............................................................169
The BeforeDoubleClick event ...........................................................169
The BeforeRightClick event ..............................................................169
The Change event...............................................................................170
Events Not Associated with Objects .........................................................172
The OnTime event..............................................................................172
Keypress events..................................................................................174

Chapter 12: Error-Handling Techniques . . . . . . . . . . . . . . . . . . . . . . . . .177


Types of Errors .............................................................................................177
An Erroneous Example ................................................................................178
The macro’s not quite perfect ..........................................................179
The macro is still not perfect............................................................180
Is the macro perfect yet?...................................................................180
Giving up on perfection .....................................................................181
Handling Errors Another Way.....................................................................182
Revisiting the EnterSquareRoot procedure ...................................182
About the On Error statement ..........................................................183

TEAM LinG
xii Excel 2007 VBA Programming For Dummies

Handling Errors: The Details ......................................................................184


Resuming after an error.....................................................................184
Error handling in a nutshell ..............................................................186
Knowing when to ignore errors ........................................................186
Identifying specific errors .................................................................187
An Intentional Error .....................................................................................188

Chapter 13: Bug Extermination Techniques . . . . . . . . . . . . . . . . . . . . .191


Species of Bugs.............................................................................................191
Identifying Bugs............................................................................................192
Debugging Techniques ................................................................................193
Examining your code .........................................................................193
Using the MsgBox function ...............................................................194
Inserting Debug.Print statements ....................................................195
Using the VBA debugger....................................................................196
About the Debugger.....................................................................................196
Setting breakpoints in your code .....................................................196
Using the Watch window ...................................................................199
Using the Locals Window ..................................................................201
Bug Reduction Tips......................................................................................201

Chapter 14: VBA Programming Examples . . . . . . . . . . . . . . . . . . . . . . .203


Working with Ranges ...................................................................................203
Copying a range ..................................................................................204
Copying a variable-sized range.........................................................205
Selecting to the end of a row or column..........................................206
Selecting a row or column.................................................................207
Moving a range ...................................................................................207
Looping through a range efficiently.................................................208
Prompting for a cell value .................................................................209
Determining the selection type .......................................................210
Identifying a multiple selection ........................................................211
Changing Excel Settings ..............................................................................211
Changing Boolean settings................................................................212
Changing non-Boolean settings ........................................................212
Working with Charts ....................................................................................213
Modifying the chart type...................................................................214
Looping through the ChartObjects collection................................214
Modifying chart properties ...............................................................215
Applying chart formatting.................................................................215
VBA Speed Tips ............................................................................................216
Turning off screen updating..............................................................216
Turning off automatic calculation ....................................................217
Eliminating those pesky alert messages .........................................218
Simplifying object references............................................................219
Declaring variable types....................................................................219
Using the With-End With structure ............................................................220

TEAM LinG
Table of Contents xiii
Part IV: Communicating with Your Users.....................221
Chapter 15: Simple Dialog Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .223
Why Create UserForms?..............................................................................223
The MsgBox Function ..................................................................................224
Displaying a simple message box.....................................................225
Getting a response from a message box..........................................225
Customizing message boxes .............................................................226
The InputBox Function................................................................................229
InputBox syntax..................................................................................229
An InputBox example.........................................................................229
The GetOpenFilename Method...................................................................231
The syntax...........................................................................................232
A GetOpenFilename example............................................................232
Selecting multiple files.......................................................................234
The GetSaveAsFilename Method ...............................................................235
Getting a Folder Name .................................................................................236
Displaying Excel’s Built-in Dialog Boxes....................................................236

Chapter 16: UserForm Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .239


Knowing When to Use a UserForm ............................................................239
Creating UserForms: An Overview.............................................................240
Working with UserForms.............................................................................241
Inserting a new UserForm .................................................................241
Adding controls to a UserForm ........................................................242
Changing properties for a UserForm control..................................243
Viewing the UserForm Code window...............................................244
Displaying a UserForm.......................................................................245
Using information from a UserForm ................................................245
A UserForm Example ...................................................................................246
Creating the UserForm.......................................................................246
Adding the CommandButtons ..........................................................247
Adding the OptionButtons ................................................................248
Adding event-handler procedures....................................................250
Creating a macro to display the dialog box ....................................251
Making the macro available ..............................................................252
Testing the macro...............................................................................253

Chapter 17: Using UserForm Controls . . . . . . . . . . . . . . . . . . . . . . . . . .255


Getting Started with Dialog Box Controls .................................................255
Adding controls ..................................................................................255
Introducing control properties.........................................................257
Dialog Box Controls: The Details ...............................................................259
CheckBox control ...............................................................................259
ComboBox control .............................................................................260
CommandButton control...................................................................261

TEAM LinG
xiv Excel 2007 VBA Programming For Dummies

Frame control......................................................................................262
Image control ......................................................................................262
Label control .......................................................................................263
ListBox control ...................................................................................264
MultiPage control ...............................................................................265
OptionButton control.........................................................................266
RefEdit control ....................................................................................267
ScrollBar control.................................................................................267
SpinButton control .............................................................................268
TabStrip control..................................................................................269
TextBox control ..................................................................................269
ToggleButton control .........................................................................270
Working with Dialog Box Controls .............................................................270
Moving and resizing controls............................................................270
Aligning and spacing controls ..........................................................271
Accommodating keyboard users......................................................272
Testing a UserForm ............................................................................273
Dialog Box Aesthetics..................................................................................274

Chapter 18: UserForm Techniques and Tricks . . . . . . . . . . . . . . . . . . .275


Using Dialog Boxes.......................................................................................275
A UserForm Example ...................................................................................275
Creating the dialog box......................................................................276
Writing code to display the dialog box............................................278
Making the macro available ..............................................................279
Trying out your dialog box ...............................................................279
Adding event-handler procedures....................................................280
Validating the data..............................................................................282
Now the dialog box works.................................................................282
More UserForm Examples...........................................................................282
A ListBox example..............................................................................282
Selecting a range.................................................................................287
Using multiple sets of OptionButtons..............................................288
Using a SpinButton and a TextBox ...................................................289
Using a UserForm as a progress indicator ......................................291
Creating a tabbed dialog box ............................................................295
Displaying a chart in a dialog box ....................................................296
A Dialog Box Checklist.................................................................................297

Chapter 19: Accessing Your Macros


Through the User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .299
CommandBars and Excel 2007 ...................................................................299
Excel 2007 Ribbon Customization..............................................................301
Working with CommandBars ......................................................................304
Commanding the CommandBars collection ...................................304
Listing all shortcut menus.................................................................304

TEAM LinG
Random documents with unrelated
content Scribd suggests to you:
THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the free


distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund
from the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only be


used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law
in the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name associated
with the work. You can easily comply with the terms of this
agreement by keeping this work in the same format with its attached
full Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.

1.E. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears,
or with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning
of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookultra.com

You might also like