Introduction |
|
xxxiii | |
Part I: Introduction to Excel VBA |
|
1 | (286) |
|
Chapter 1 Essentials of Spreadsheet Application Development |
|
|
3 | (16) |
|
What Is a Spreadsheet Application? |
|
|
3 | (1) |
|
Steps for Application Development |
|
|
4 | (1) |
|
|
5 | (1) |
|
Planning an Application That Meets User Needs |
|
|
6 | (1) |
|
Determining the Most Appropriate User Interface |
|
|
7 | (5) |
|
|
8 | (1) |
|
Customizing shortcut menus |
|
|
8 | (1) |
|
|
9 | (1) |
|
Creating custom dialog boxes |
|
|
9 | (1) |
|
Using ActiveX controls on a worksheet |
|
|
10 | (2) |
|
Executing the development effort |
|
|
12 | (1) |
|
Concerning Yourself with the End User |
|
|
12 | (5) |
|
|
12 | (1) |
|
Making the application bulletproof |
|
|
13 | (2) |
|
Making the application aesthetically appealing and intuitive |
|
|
15 | (1) |
|
Creating a user Help system |
|
|
16 | (1) |
|
Documenting the development effort |
|
|
16 | (1) |
|
Distributing the application to the user |
|
|
16 | (1) |
|
Updating the application when necessary |
|
|
17 | (1) |
|
|
17 | (2) |
|
The user's installed version of Excel |
|
|
17 | (1) |
|
|
17 | (1) |
|
|
18 | (1) |
|
|
18 | (1) |
|
Chapter 2 Introducing Visual Basic for Applications |
|
|
19 | (42) |
|
Getting a Head Start with the Macro Recorder |
|
|
19 | (13) |
|
Creating your first macro |
|
|
20 | (3) |
|
|
21 | (1) |
|
|
22 | (1) |
|
|
22 | (1) |
|
Comparing absolute and relative macro recording |
|
|
23 | (5) |
|
Recording macros with absolute references |
|
|
23 | (3) |
|
Recording macros with relative references |
|
|
26 | (2) |
|
Other macro recording concepts |
|
|
28 | (4) |
|
|
28 | (1) |
|
|
28 | (1) |
|
Storing macros in your Personal Macro Workbook |
|
|
29 | (1) |
|
Assigning a macro to a button and other form controls |
|
|
30 | (1) |
|
Placing a macro on the Quick Access toolbar |
|
|
31 | (1) |
|
Working with the Visual Basic Editor |
|
|
32 | (11) |
|
Understanding VBE components |
|
|
32 | (2) |
|
|
32 | (1) |
|
|
33 | (1) |
|
|
33 | (1) |
|
|
33 | (1) |
|
|
34 | (1) |
|
Working with the Project window |
|
|
34 | (2) |
|
|
35 | (1) |
|
|
35 | (1) |
|
Working with a Code window |
|
|
36 | (3) |
|
Minimizing and maximizing windows |
|
|
36 | (1) |
|
Getting VBA code into a module |
|
|
37 | (2) |
|
Customizing the VBA environment |
|
|
39 | (2) |
|
|
39 | (2) |
|
|
41 | (1) |
|
|
41 | (1) |
|
|
42 | (1) |
|
|
43 | (5) |
|
|
43 | (1) |
|
Understanding collections |
|
|
44 | (1) |
|
|
44 | (4) |
|
Specifying properties for the active object |
|
|
45 | (1) |
|
|
46 | (2) |
|
Deep Dive: Working with Range Objects |
|
|
48 | (4) |
|
Finding the properties of the Range object |
|
|
48 | (1) |
|
|
48 | (1) |
|
|
49 | (2) |
|
|
51 | (1) |
|
Essential Concepts to Remember |
|
|
52 | (2) |
|
Don't Panic-You Are Not Alone |
|
|
54 | (7) |
|
Read the rest of the book |
|
|
54 | (1) |
|
Let Excel help write your macro |
|
|
54 | (1) |
|
|
55 | (1) |
|
Location matters when asking for help |
|
|
55 | (1) |
|
You need to be connected to the Internet |
|
|
55 | (1) |
|
|
55 | (2) |
|
Pilfer code from the Internet |
|
|
57 | (1) |
|
|
57 | (1) |
|
|
58 | (1) |
|
Mine YouTube for video training |
|
|
58 | (1) |
|
Learn from the Microsoft Office Dev Center |
|
|
58 | (1) |
|
Dissect the other Excel files in your organization |
|
|
58 | (1) |
|
Ask your local Excel genius |
|
|
59 | (2) |
|
Chapter 3 VBA Programming Fundamentals |
|
|
61 | (44) |
|
VBA Language Elements: An Overview |
|
|
61 | (2) |
|
|
63 | (2) |
|
Variables, Data Types, and Constants |
|
|
65 | (11) |
|
|
66 | (1) |
|
|
67 | (3) |
|
|
68 | (1) |
|
Forcing yourself to declare all variables |
|
|
69 | (1) |
|
|
70 | (2) |
|
|
70 | (1) |
|
|
71 | (1) |
|
|
72 | (1) |
|
|
72 | (1) |
|
|
72 | (2) |
|
|
73 | (1) |
|
Using predefined constants |
|
|
73 | (1) |
|
|
74 | (1) |
|
|
74 | (2) |
|
|
76 | (2) |
|
|
78 | (1) |
|
|
78 | (2) |
|
Declaring multidimensional arrays |
|
|
79 | (1) |
|
|
79 | (1) |
|
|
80 | (1) |
|
|
81 | (1) |
|
|
82 | (3) |
|
Manipulating Objects and Collections |
|
|
85 | (3) |
|
|
85 | (1) |
|
|
86 | (2) |
|
Controlling Code Execution |
|
|
88 | (17) |
|
|
88 | (1) |
|
|
89 | (4) |
|
|
93 | (3) |
|
Looping blocks of instructions |
|
|
96 | (9) |
|
|
97 | (3) |
|
|
100 | (2) |
|
|
102 | (3) |
|
Chapter 4 Working with VBA Sub Procedures |
|
|
105 | (38) |
|
|
105 | (3) |
|
Declaring a Sub procedure |
|
|
106 | (1) |
|
|
107 | (1) |
|
|
107 | (1) |
|
|
107 | (1) |
|
|
108 | (11) |
|
Executing a procedure with the Run Sub/UserForm command |
|
|
109 | (1) |
|
Executing a procedure from the Macro dialog box |
|
|
109 | (1) |
|
Executing a procedure with a Ctrl+shortcut key combination |
|
|
110 | (1) |
|
Executing a procedure from the Ribbon |
|
|
111 | (1) |
|
Executing a procedure from a customized shortcut menu |
|
|
112 | (1) |
|
Executing a procedure from another procedure |
|
|
112 | (5) |
|
Calling a procedure in a different module |
|
|
113 | (1) |
|
Calling a procedure in a different workbook |
|
|
114 | (3) |
|
Executing a procedure by clicking an object |
|
|
117 | (1) |
|
Executing a procedure when an event occurs |
|
|
118 | (1) |
|
Executing a procedure from the Immediate window |
|
|
118 | (1) |
|
Passing Arguments to Procedures |
|
|
119 | (4) |
|
Error-Handling Techniques |
|
|
123 | (4) |
|
|
123 | (1) |
|
|
124 | (3) |
|
A Realistic Example That Uses Sub Procedures |
|
|
127 | (13) |
|
|
127 | (1) |
|
|
128 | (1) |
|
|
128 | (1) |
|
|
129 | (1) |
|
Some preliminary recording |
|
|
129 | (1) |
|
|
130 | (1) |
|
|
131 | (1) |
|
Writing the Sort procedure |
|
|
132 | (5) |
|
|
137 | (1) |
|
|
137 | (3) |
|
|
140 | (1) |
|
|
141 | (2) |
|
Chapter 5 Creating Function Procedures |
|
|
143 | (40) |
|
Sub Procedures vs. Function Procedures |
|
|
143 | (1) |
|
Why Create Custom Functions? |
|
|
144 | (1) |
|
An Introductory Function Example |
|
|
144 | (4) |
|
Using the function in a worksheet |
|
|
145 | (1) |
|
Using the function in a VBA procedure |
|
|
146 | (1) |
|
Analyzing the custom function |
|
|
146 | (2) |
|
|
148 | (5) |
|
|
150 | (1) |
|
Executing function procedures |
|
|
150 | (3) |
|
|
150 | (1) |
|
|
150 | (1) |
|
In a conditional formatting formula |
|
|
151 | (2) |
|
From the VBE Immediate Window |
|
|
153 | (1) |
|
|
153 | (1) |
|
|
153 | (14) |
|
Functions with no argument |
|
|
153 | (3) |
|
A function with one argument |
|
|
156 | (3) |
|
A function with two arguments |
|
|
159 | (1) |
|
A function with an array argument |
|
|
159 | (1) |
|
A function with optional arguments |
|
|
160 | (2) |
|
A function that returns a VBA array |
|
|
162 | (3) |
|
A function that returns an error value |
|
|
165 | (1) |
|
A function with an indefinite number of arguments |
|
|
166 | (1) |
|
Emulating Excel's SUM Function |
|
|
167 | (3) |
|
|
170 | (2) |
|
|
172 | (1) |
|
Dealing with the Insert Function Dialog Box |
|
|
173 | (5) |
|
Using the MacroOptions method |
|
|
174 | (2) |
|
Specifying a function category |
|
|
176 | (1) |
|
Adding a function description manually |
|
|
177 | (1) |
|
Using Add-Ins to Store Custom Functions |
|
|
178 | (1) |
|
|
178 | (5) |
|
|
179 | (1) |
|
Determining the Windows directory |
|
|
179 | (2) |
|
|
181 | (1) |
|
Learning more about API functions |
|
|
181 | (2) |
|
Chapter 6 Understanding Excel's Events |
|
|
183 | (34) |
|
What You Should Know About Events |
|
|
183 | (6) |
|
Understanding event sequences |
|
|
184 | (1) |
|
Where to put event-handler procedures |
|
|
184 | (2) |
|
|
186 | (1) |
|
Entering event-handler code |
|
|
187 | (1) |
|
Event-handler procedures that use arguments |
|
|
188 | (1) |
|
Getting Acquainted with Workbook-Level Events |
|
|
189 | (8) |
|
|
191 | (1) |
|
|
191 | (1) |
|
|
192 | (1) |
|
|
192 | (1) |
|
|
192 | (1) |
|
|
193 | (1) |
|
|
193 | (2) |
|
Updating a header or footer |
|
|
193 | (1) |
|
Hiding columns before printing |
|
|
194 | (1) |
|
|
195 | (2) |
|
Examining Worksheet Events |
|
|
197 | (9) |
|
|
198 | (1) |
|
Monitoring a specific range for changes |
|
|
199 | (4) |
|
Monitoring a range to make formulas bold |
|
|
199 | (1) |
|
Monitoring a range to validate data entry |
|
|
200 | (3) |
|
The SelectionChange event |
|
|
203 | (1) |
|
The BeforeDoubleClick event |
|
|
204 | (1) |
|
The BeforeRightClick event |
|
|
205 | (1) |
|
Monitoring with Application Events |
|
|
206 | (11) |
|
Enabling Application-level events |
|
|
206 | (2) |
|
Determining when a workbook is opened |
|
|
208 | (1) |
|
Monitoring Application-level events |
|
|
209 | (1) |
|
Accessing events not associated with an object |
|
|
210 | (1) |
|
|
210 | (2) |
|
|
212 | (6) |
|
|
212 | (1) |
|
|
213 | (1) |
|
|
214 | (3) |
|
Chapter 7 VBA Programming Examples and Techniques |
|
|
217 | (70) |
|
|
217 | (1) |
|
|
218 | (28) |
|
|
218 | (1) |
|
|
219 | (1) |
|
Copying a variably sized range |
|
|
219 | (2) |
|
Selecting or otherwise identifying various types of ranges |
|
|
221 | (2) |
|
|
223 | (1) |
|
Prompting for a cell value |
|
|
223 | (2) |
|
Entering a value in the next empty cell |
|
|
225 | (1) |
|
Pausing a macro to get a user-selected range |
|
|
226 | (2) |
|
|
228 | (1) |
|
Determining the type of selected range |
|
|
228 | (2) |
|
Looping through a selected range efficiently |
|
|
230 | (3) |
|
|
233 | (1) |
|
Duplicating rows a variable number of times |
|
|
234 | (2) |
|
Determining whether a range is contained in another range |
|
|
236 | (1) |
|
Determining a cell's data type |
|
|
236 | (2) |
|
Reading and writing ranges |
|
|
238 | (1) |
|
A better way to write to a range |
|
|
239 | (2) |
|
Transferring one-dimensional arrays |
|
|
241 | (1) |
|
Transferring a range to a variant array |
|
|
242 | (1) |
|
|
243 | (1) |
|
Copying a noncontiguous range |
|
|
244 | (2) |
|
Working with Workbooks and Sheets |
|
|
246 | (5) |
|
|
246 | (1) |
|
Saving and closing all workbooks |
|
|
247 | (1) |
|
Hiding all but the selection |
|
|
247 | (2) |
|
Creating a hyperlink table of contents |
|
|
249 | (1) |
|
|
250 | (1) |
|
|
251 | (7) |
|
Toggling a Boolean property |
|
|
251 | (1) |
|
Displaying the date and time |
|
|
251 | (2) |
|
|
253 | (1) |
|
|
254 | (2) |
|
|
256 | (1) |
|
Processing a series of files |
|
|
256 | (2) |
|
Some Useful Functions for Use in Your Code |
|
|
258 | (5) |
|
|
259 | (1) |
|
The FileNameOnly function |
|
|
259 | (1) |
|
|
259 | (1) |
|
The RangeNameExists function |
|
|
260 | (1) |
|
|
260 | (1) |
|
The WorkbookIsOpen function |
|
|
261 | (1) |
|
Retrieving a value from a closed workbook |
|
|
262 | (1) |
|
Some Useful Worksheet Functions |
|
|
263 | (15) |
|
Returning cell formatting information |
|
|
264 | (1) |
|
|
265 | (1) |
|
Displaying the date when a file was saved or printed |
|
|
265 | (1) |
|
Understanding object parents |
|
|
266 | (1) |
|
Counting cells between two values |
|
|
267 | (1) |
|
Determining the last nonempty cell in a column or row |
|
|
268 | (1) |
|
Does a string match a pattern? |
|
|
269 | (1) |
|
Extracting the nth element from a string |
|
|
270 | (1) |
|
|
271 | (1) |
|
A multifunctional function |
|
|
272 | (1) |
|
|
273 | (1) |
|
Returning the maximum value across all worksheets |
|
|
274 | (1) |
|
Returning an array of nonduplicated random integers |
|
|
275 | (1) |
|
|
276 | (1) |
|
|
277 | (1) |
|
|
278 | (11) |
|
Understanding API declarations |
|
|
279 | (1) |
|
32-bit vs. 64-bit declarations |
|
|
279 | (1) |
|
Determining file associations |
|
|
280 | (1) |
|
Determining default printer information |
|
|
281 | (1) |
|
Determining video display information |
|
|
282 | (1) |
|
Reading from and writing to the Registry |
|
|
283 | (6) |
|
Reading from the Registry |
|
|
284 | (1) |
|
|
284 | (3) |
Part II: Advanced VBA Techniques |
|
287 | (130) |
|
Chapter 8 Working with Pivot Tables |
|
|
289 | (16) |
|
An Introductory Pivot Table Example |
|
|
289 | (6) |
|
|
290 | (2) |
|
Examining the recorded code for the pivot table |
|
|
292 | (1) |
|
Cleaning up the recorded pivot table code |
|
|
292 | (3) |
|
Creating a More Complex Pivot Table |
|
|
295 | (4) |
|
The code that created the pivot table |
|
|
296 | (1) |
|
How the more complex pivot table works |
|
|
297 | (2) |
|
Creating Multiple Pivot Tables |
|
|
299 | (3) |
|
Creating a Reverse Pivot Table |
|
|
302 | (3) |
|
Chapter 9 Working with Charts |
|
|
305 | (46) |
|
Getting the Inside Scoop on Charts |
|
|
305 | (3) |
|
|
305 | (1) |
|
The macro recorder and charts |
|
|
306 | (1) |
|
|
306 | (2) |
|
Creating an Embedded Chart |
|
|
308 | (1) |
|
Creating a Chart on a Chart Sheet |
|
|
309 | (1) |
|
|
309 | (1) |
|
Using VBA to Activate a Chart |
|
|
310 | (1) |
|
|
311 | (1) |
|
Using VBA to Deactivate a Chart |
|
|
312 | (1) |
|
Determining Whether a Chart Is Activated |
|
|
313 | (1) |
|
Deleting from the ChartObjects or Charts Collection |
|
|
313 | (1) |
|
Looping Through All Charts |
|
|
314 | (3) |
|
Sizing and Aligning ChartObjects |
|
|
317 | (1) |
|
|
318 | (3) |
|
|
321 | (1) |
|
|
321 | (1) |
|
Changing the Data Used in a Chart |
|
|
322 | (6) |
|
Changing chart data based on the active cell |
|
|
324 | (1) |
|
Using VBA to determine the ranges used in a chart |
|
|
325 | (3) |
|
Using VBA to Display Custom Data Labels on a Chart |
|
|
328 | (3) |
|
Displaying a Chart in a UserForm |
|
|
331 | (3) |
|
Understanding Chart Events |
|
|
334 | (6) |
|
An example of using Chart events |
|
|
334 | (3) |
|
Enabling events for an embedded chart |
|
|
337 | (1) |
|
|
337 | (1) |
|
Declare a public Chart object |
|
|
337 | (1) |
|
Connect the declared object with your chart |
|
|
337 | (1) |
|
Write event-handler procedures for the chart class |
|
|
337 | (1) |
|
Example: Using Chart events with an embedded chart |
|
|
338 | (2) |
|
Discovering VBA Charting Tricks |
|
|
340 | (7) |
|
Printing embedded charts on a full page |
|
|
340 | (1) |
|
|
341 | (2) |
|
Displaying text with the MouseOver event |
|
|
343 | (2) |
|
|
345 | (2) |
|
Working with Sparkline Charts |
|
|
347 | (4) |
|
Chapter 10 Interacting with Other Applications |
|
|
351 | (26) |
|
Understanding Microsoft Office Automation |
|
|
351 | (3) |
|
Understanding the concept of binding |
|
|
351 | (3) |
|
|
352 | (1) |
|
|
352 | (2) |
|
A simple automation example |
|
|
354 | (1) |
|
Automating Access from Excel |
|
|
354 | (2) |
|
Running an Access query from Excel |
|
|
354 | (2) |
|
Running an Access macro from Excel |
|
|
356 | (1) |
|
Automating Word from Excel |
|
|
356 | (4) |
|
Sending Excel data to a Word document |
|
|
357 | (1) |
|
Simulating Mail Merge with a Word document |
|
|
358 | (2) |
|
Automating PowerPoint from Excel |
|
|
360 | (5) |
|
Sending Excel data to a PowerPoint presentation |
|
|
361 | (1) |
|
Sending all Excel charts to a PowerPoint presentation |
|
|
362 | (1) |
|
Convert a workbook into a PowerPoint presentation |
|
|
363 | (2) |
|
Automating Outlook from Excel |
|
|
365 | (4) |
|
Mailing the active workbook as an attachment |
|
|
365 | (1) |
|
Mailing a specific range as an attachment |
|
|
366 | (1) |
|
Mailing a Single Sheet as an Attachment |
|
|
367 | (1) |
|
Mailing All E-mail Addresses in Your Contact List |
|
|
368 | (1) |
|
Starting Other Applications from Excel |
|
|
369 | (8) |
|
Using the VBA Shell function |
|
|
370 | (2) |
|
Using the Windows ShellExecute API function |
|
|
372 | (1) |
|
|
373 | (1) |
|
Running Control Panel Dialog Boxes |
|
|
374 | (3) |
|
Chapter 11 Working with External Data and Files |
|
|
377 | (40) |
|
Working with External Data Connections |
|
|
377 | (1) |
|
|
377 | (13) |
|
Understanding query steps |
|
|
383 | (2) |
|
Refreshing Power Query data |
|
|
385 | (1) |
|
Managing existing queries |
|
|
385 | (1) |
|
Using VBA to create dynamic connections |
|
|
386 | (3) |
|
Iterating through all connections in a workbook |
|
|
389 | (1) |
|
Using ADO and VBA to Pull External Data |
|
|
390 | (7) |
|
|
390 | (2) |
|
|
392 | (1) |
|
Referencing the ADO object library |
|
|
392 | (2) |
|
Putting it all together in code |
|
|
394 | (1) |
|
Using ADO with the active workbook |
|
|
395 | (2) |
|
Querying data from an Excel workbook |
|
|
395 | (1) |
|
Appending records to an existing Excel table |
|
|
396 | (1) |
|
|
397 | (4) |
|
|
398 | (1) |
|
|
399 | (1) |
|
|
399 | (1) |
|
|
399 | (1) |
|
Determining or setting the file position |
|
|
399 | (1) |
|
Statements for reading and writing |
|
|
400 | (1) |
|
Text File Manipulation Examples |
|
|
401 | (4) |
|
Importing data in a text file |
|
|
401 | (1) |
|
Exporting a range to a text file |
|
|
401 | (1) |
|
Importing a text file to a range |
|
|
402 | (1) |
|
|
403 | (1) |
|
|
404 | (1) |
|
Performing Common File Operations |
|
|
405 | (8) |
|
Using VBA file-related statements |
|
|
406 | (4) |
|
A VBA function to determine whether a file exists |
|
|
406 | (1) |
|
A VBA function to determine whether a path exists |
|
|
406 | (1) |
|
A VBA procedure to display a list of files in a directory |
|
|
407 | (2) |
|
A recursive VBA procedure to display a list of files in nested directories |
|
|
409 | (1) |
|
Using the FileSystemObject object |
|
|
410 | (3) |
|
Using FileSystemObject to determine whether a file exists |
|
|
411 | (1) |
|
Using FileSystemObject to determine whether a path exists |
|
|
412 | (1) |
|
Using FileSystemObject to list information about all available disk drives |
|
|
412 | (1) |
|
Zipping and Unzipping Files |
|
|
413 | (6) |
|
|
413 | (2) |
|
|
415 | (2) |
Part III: Working with UserForms |
|
417 | (150) |
|
Chapter 12 Leveraging Custom Dialog Boxes |
|
|
419 | (22) |
|
Alternatives to UserForms |
|
|
419 | (1) |
|
|
419 | (7) |
|
Using the VBA InputBox function |
|
|
419 | (3) |
|
Using the Application.InputBox method |
|
|
422 | (4) |
|
Using the VBA MsgBox Function |
|
|
426 | (5) |
|
Using the Excel GetOpenFilename Method |
|
|
431 | (3) |
|
Using the Excel GetSaveAsFilename Method |
|
|
434 | (1) |
|
|
435 | (1) |
|
Displaying Excel's Built-in Dialog Boxes |
|
|
435 | (3) |
|
|
438 | (3) |
|
Making the data form accessible |
|
|
438 | (2) |
|
Displaying a data form by using VBA |
|
|
440 | (1) |
|
Chapter 13 Introducing UserForms |
|
|
441 | (38) |
|
How Excel Handles Custom Dialog Boxes |
|
|
441 | (1) |
|
|
442 | (1) |
|
Adding Controls to a UserForm |
|
|
443 | (1) |
|
|
443 | (5) |
|
|
444 | (1) |
|
|
445 | (1) |
|
|
445 | (1) |
|
|
445 | (1) |
|
|
445 | (1) |
|
|
445 | (1) |
|
|
445 | (1) |
|
|
445 | (1) |
|
|
446 | (1) |
|
|
446 | (1) |
|
|
446 | (1) |
|
|
446 | (1) |
|
|
446 | (1) |
|
|
446 | (1) |
|
|
446 | (2) |
|
Adjusting UserForm Controls |
|
|
448 | (2) |
|
Adjusting a Control's Properties |
|
|
450 | (6) |
|
Using the Properties window |
|
|
450 | (2) |
|
|
452 | (2) |
|
Accommodating keyboard users |
|
|
454 | (2) |
|
Changing the tab order of controls |
|
|
454 | (1) |
|
|
455 | (1) |
|
|
456 | (2) |
|
Adjusting the display position |
|
|
456 | (1) |
|
Displaying a modeless UserForm |
|
|
457 | (1) |
|
Displaying a UserForm based on a variable |
|
|
457 | (1) |
|
|
458 | (1) |
|
About event-handler procedures |
|
|
458 | (1) |
|
|
458 | (2) |
|
Creating a UserForm: An Example |
|
|
460 | (13) |
|
|
460 | (3) |
|
Writing code to display the dialog box |
|
|
463 | (1) |
|
|
464 | (1) |
|
Adding event-handler procedures |
|
|
465 | (1) |
|
|
466 | (1) |
|
|
467 | (1) |
|
|
468 | (2) |
|
|
469 | (1) |
|
Keyboard-initiated events |
|
|
469 | (1) |
|
What about code-initiated events? |
|
|
470 | (1) |
|
Pairing a SpinButton with a TextBox |
|
|
470 | (3) |
|
Referencing UserForm Controls |
|
|
473 | (1) |
|
|
474 | (3) |
|
Adding new pages to the Toolbox |
|
|
474 | (1) |
|
Customizing or combining controls |
|
|
474 | (1) |
|
Adding other ActiveX controls |
|
|
475 | (2) |
|
Creating UserForm Templates |
|
|
477 | (1) |
|
|
478 | (1) |
|
Chapter 14 Looking at UserForm Examples |
|
|
479 | (40) |
|
Creating a UserForm "Menu" |
|
|
479 | (2) |
|
Using CommandButtons in a UserForm |
|
|
479 | (1) |
|
Using a list box in a UserForm |
|
|
480 | (1) |
|
Selecting Ranges from a UserForm |
|
|
481 | (2) |
|
|
483 | (3) |
|
Disabling a UserForm's Close Button |
|
|
486 | (1) |
|
Changing a UserForm's Size |
|
|
487 | (1) |
|
Zooming and Scrolling a Sheet from a UserForm |
|
|
488 | (2) |
|
Exploring ListBox Techniques |
|
|
490 | (22) |
|
Adding items to a ListBox control |
|
|
491 | (5) |
|
Adding items to a list box at design time |
|
|
491 | (1) |
|
Adding items to a list box at run-time |
|
|
492 | (2) |
|
Adding only unique items to a list box |
|
|
494 | (2) |
|
Determining the selected item in a list box |
|
|
496 | (1) |
|
Determining multiple selections in a list box |
|
|
497 | (1) |
|
Multiple lists in a single list box |
|
|
498 | (1) |
|
|
498 | (2) |
|
Moving items in a list box |
|
|
500 | (2) |
|
Working with multicolumn ListBox controls |
|
|
502 | (3) |
|
Using a list box to select worksheet rows |
|
|
505 | (2) |
|
Using a list box to activate a sheet |
|
|
507 | (3) |
|
Using a text box to filter a list box |
|
|
510 | (2) |
|
Using the MultiPage Control in a UserForm |
|
|
512 | (1) |
|
Using an External Control |
|
|
513 | (3) |
|
|
516 | (3) |
|
Chapter 15 Implementing Advanced UserForm Techniques |
|
|
519 | (48) |
|
|
519 | (4) |
|
Displaying a Progress Indicator |
|
|
523 | (12) |
|
Creating a stand-alone progress indicator |
|
|
524 | (4) |
|
Building the stand-alone progress indicator UserForm |
|
|
525 | (1) |
|
Creating the code that increments the progress bar |
|
|
526 | (1) |
|
Calling the stand-alone progress indicator from your code |
|
|
527 | (1) |
|
Benefits of a stand-alone progress indicator |
|
|
528 | (1) |
|
Showing a progress indicator that's integrated into a UserForm |
|
|
528 | (4) |
|
Modifying your UserForm for a progress indicator with a MultiPage control |
|
|
528 | (2) |
|
Inserting the UpdateProgress procedure for a progress indicator with a MultiPage control |
|
|
530 | (1) |
|
Modifying your procedure for a progress indicator with a MultiPage control |
|
|
530 | (1) |
|
How a progress indicator with a MultiPage control works |
|
|
531 | (1) |
|
Showing a progress indicator without using a MultiPage control |
|
|
531 | (1) |
|
Creating a nongraphical progress indicator |
|
|
532 | (3) |
|
Creating the UserForm to display the steps |
|
|
533 | (1) |
|
Modifying the calling procedure to use the progress indicator |
|
|
533 | (1) |
|
|
534 | (1) |
|
Setting up the MultiPage control for the wizard |
|
|
535 | (6) |
|
Adding the buttons to the wizard's UserForm |
|
|
536 | (1) |
|
Programming the wizard's buttons |
|
|
536 | (2) |
|
Programming dependencies in a wizard |
|
|
538 | (2) |
|
Performing the task with the wizard |
|
|
540 | (1) |
|
Emulating the MsgBox Function |
|
|
541 | (4) |
|
MsgBox emulation: MyMsgBox code |
|
|
542 | (1) |
|
How the MyMsgBox function works |
|
|
543 | (2) |
|
Using the MyMsgBox function |
|
|
545 | (1) |
|
A UserForm with Movable Controls |
|
|
545 | (1) |
|
A UserForm with No Title Bar |
|
|
546 | (2) |
|
Simulating a Toolbar with a UserForm |
|
|
548 | (2) |
|
Emulating a Task Pane with a UserForm |
|
|
550 | (1) |
|
|
551 | (5) |
|
Handling Multiple UserForm Controls with One Event Handler |
|
|
556 | (3) |
|
Selecting a Color in a UserForm |
|
|
559 | (2) |
|
Displaying a Chart in a UserForm |
|
|
561 | (1) |
|
Saving a chart as a GIF file |
|
|
562 | (1) |
|
Changing the Image control's Picture property |
|
|
562 | (1) |
|
Making a UserForm Semitransparent |
|
|
562 | (1) |
|
|
563 | (2) |
|
Video Poker on a UserForm |
|
|
565 | (2) |
Part IV: Developing Excel Applications |
|
567 | (146) |
|
Chapter 16 Creating and Using Add-Ins |
|
|
569 | (30) |
|
|
569 | (3) |
|
Comparing an add-in with a standard workbook |
|
|
569 | (1) |
|
|
570 | (2) |
|
Understanding Excel's Add-in Manager |
|
|
572 | (2) |
|
|
574 | (1) |
|
|
575 | (6) |
|
Adding descriptive information for the example add-in |
|
|
577 | (1) |
|
|
577 | (1) |
|
|
578 | (1) |
|
|
579 | (1) |
|
|
579 | (1) |
|
|
580 | (1) |
|
Comparing XLAM and XLSM Files |
|
|
581 | (6) |
|
XLAM file VBA collection membership |
|
|
581 | (1) |
|
Visibility of XLSM and XLAM files |
|
|
582 | (1) |
|
Worksheets and chart sheets in XLSM and XLAM files |
|
|
582 | (1) |
|
Accessing VBA procedures in an add-in |
|
|
583 | (4) |
|
Manipulating Add-Ins with VBA |
|
|
587 | (12) |
|
Adding an item to the AddIns collection |
|
|
587 | (1) |
|
Removing an item from the AddIns collection |
|
|
588 | (1) |
|
|
589 | (3) |
|
The Name property of an AddIn object |
|
|
589 | (1) |
|
The Path property of an AddIn object |
|
|
589 | (1) |
|
The FullName property of an AddIn object |
|
|
589 | (1) |
|
The Title property of an AddIn object |
|
|
590 | (1) |
|
The Comments property of an AddIn object |
|
|
590 | (1) |
|
The Installed property of an AddIn object |
|
|
590 | (2) |
|
Accessing an add-in as a workbook |
|
|
592 | (1) |
|
|
593 | (1) |
|
Optimizing the Performance of Add-Ins |
|
|
593 | (1) |
|
Special Problems with Add-Ins |
|
|
594 | (7) |
|
Ensuring that an add-in is installed |
|
|
594 | (2) |
|
Referencing other files from an add-in |
|
|
596 | (3) |
|
Chapter 17 Working with the Ribbon |
|
|
599 | (38) |
|
|
599 | (2) |
|
|
601 | (5) |
|
Adding a button to the Ribbon |
|
|
601 | (3) |
|
Adding a button to the Quick Access toolbar |
|
|
604 | (1) |
|
Understanding the limitations of Ribbon customization |
|
|
605 | (1) |
|
|
606 | (22) |
|
Adding a button to an existing tab |
|
|
607 | (6) |
|
|
611 | (1) |
|
|
612 | (1) |
|
|
612 | (1) |
|
Adding a check box to an existing tab |
|
|
613 | (3) |
|
|
614 | (1) |
|
|
615 | (1) |
|
|
616 | (9) |
|
|
617 | (1) |
|
|
617 | (1) |
|
|
618 | (7) |
|
A dynamicMenu control example |
|
|
625 | (2) |
|
More on Ribbon customization |
|
|
627 | (1) |
|
Using VBA with the Ribbon |
|
|
628 | (4) |
|
Accessing a Ribbon control |
|
|
629 | (1) |
|
|
630 | (1) |
|
|
631 | (1) |
|
Creating an Old-Style Toolbar |
|
|
632 | (5) |
|
Limitations of old-style toolbars |
|
|
632 | (1) |
|
|
632 | (5) |
|
Chapter 18 Working with Shortcut Menus |
|
|
637 | (22) |
|
|
637 | (3) |
|
|
637 | (1) |
|
|
638 | (1) |
|
|
639 | (1) |
|
Referring to Controls in a CommandBar |
|
|
640 | (1) |
|
Properties of CommandBar Controls |
|
|
641 | (1) |
|
Displaying All Shortcut Menu Items |
|
|
642 | (2) |
|
Using VBA to Customize Shortcut Menus |
|
|
644 | (2) |
|
Shortcut menu and the single-document interface |
|
|
644 | (2) |
|
Resetting a shortcut menu |
|
|
646 | (8) |
|
Disabling a shortcut menu |
|
|
647 | (1) |
|
Disabling shortcut menu items |
|
|
648 | (1) |
|
Adding a new item to the Cell shortcut menu |
|
|
648 | (2) |
|
Adding a submenu to a shortcut menu |
|
|
650 | (2) |
|
Limiting a shortcut menu to a single workbook |
|
|
652 | (2) |
|
Shortcut Menus and Events |
|
|
654 | (5) |
|
Adding and deleting menus automatically |
|
|
654 | (1) |
|
Disabling or hiding shortcut menu items |
|
|
654 | (1) |
|
Creating a context-sensitive shortcut menu |
|
|
655 | (4) |
|
Chapter 19 Providing Help for Your Applications |
|
|
659 | (20) |
|
Help for Your Excel Applications |
|
|
659 | (2) |
|
Help Systems That Use Excel Components |
|
|
661 | (9) |
|
Using cell comments for help |
|
|
661 | (2) |
|
Using a text box for help |
|
|
663 | (1) |
|
Using a worksheet to display help text |
|
|
664 | (1) |
|
Displaying help in a UserForm |
|
|
665 | (5) |
|
Using Label controls to display help text |
|
|
666 | (1) |
|
Using a scrolling label to display help text |
|
|
667 | (1) |
|
Using a ComboBox control to select a help topic |
|
|
668 | (2) |
|
Displaying Help in a Web Browser |
|
|
670 | (2) |
|
|
670 | (1) |
|
|
671 | (1) |
|
Using the HTML Help System |
|
|
672 | (7) |
|
Using the Help method to display HTML Help |
|
|
674 | (1) |
|
Associating a help file with your application |
|
|
675 | (1) |
|
Associating a help topic with a VBA function |
|
|
675 | (4) |
|
Chapter 20 Leveraging Class Modules |
|
|
679 | (20) |
|
|
679 | (2) |
|
|
680 | (1) |
|
|
680 | (1) |
|
|
680 | (1) |
|
Objects, properties, and methods |
|
|
681 | (1) |
|
|
681 | (4) |
|
|
682 | (1) |
|
Adding VBA code to the class module |
|
|
683 | (1) |
|
|
684 | (1) |
|
Coding Properties, Methods, and Events |
|
|
685 | (3) |
|
Programming properties of objects |
|
|
685 | (2) |
|
Programming methods for objects |
|
|
687 | (1) |
|
|
688 | (1) |
|
Exposing a QueryTable Event |
|
|
688 | (4) |
|
Creating a Class to Hold Classes |
|
|
692 | (7) |
|
Creating the CSalesRep and CSalesReps classes |
|
|
693 | (2) |
|
Creating the Clnvoice and Clnvoices classes |
|
|
695 | (1) |
|
Filling the parent classes with objects |
|
|
696 | (1) |
|
Calculating the commissions |
|
|
697 | (2) |
|
Chapter 21 Understanding Compatibility Issues |
|
|
699 | (14) |
|
|
699 | (1) |
|
Types of Compatibility Problems |
|
|
699 | (2) |
|
|
701 | (2) |
|
But Will It Work on a Mac? |
|
|
703 | (1) |
|
Dealing with 64-Bit Excel |
|
|
704 | (1) |
|
Creating an International Application |
|
|
705 | (2) |
|
Multilanguage Applications |
|
|
707 | (1) |
|
VBA Language Considerations |
|
|
708 | (1) |
|
|
708 | (1) |
|
Identifying System Settings |
|
|
709 | (2) |
|
|
711 | (2) |
Part V: Appendix |
|
713 | (12) |
|
Appendix: VBA Statements and Functions Reference |
|
|
715 | (10) |
Index |
|
725 | |