... Introduction
Welcome to Excel 2013 PowerProgramming with VBA. If your job
involves developing Excel workbooks that others will use — or if you
simply want to get the most out of Excel — you've ... Box
The VBA InputBox function
The Excel InputBox method
The VBA MsgBox Function
The Excel GetOpenFilename Method
The Excel GetSaveAsFilename Method
Prompting for a Directory
Displaying Excel& apos;s ... also applies to Excel 2003 and later
versions, I assume that you're using Excel 2013. Excel2007 and later
versions are radically different from their predecessors, but the VBA
environment...
...
know to learn VBA. In this part, I introduce you to VBA, provide programming fundamentals, and
detail how to develop VBA subroutines and functions. Chapter 11 contains many useful VBA
examples.
Part ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704
Excel 2010 PowerProgramming with VBA
Published by
Wiley Publishing, Inc.
111 River Street
Hoboken, NJ 07030-5774
www.wiley.com
Copyright ... controlling Excel s objects, and you do so by
using VBA. This concept becomes clearer in subsequent chapters.
Workbooks
The most common Excel object is a workbook. Everything that you do in Excel...
... 608
4799-2 FM.F 6/11/01 1:12 PM Page xxxiii
4799-2 FM.F 6/11/01 1:12 PM Page xvi
Excel 2002 PowerProgramming with VBA
Published by
M&T Books
An imprint of Hungry Minds, Inc.
909 Third Avenue
New ... Excel. Although the book was
written with Excel 2002 in mind, most of the material also applies to Excel 2000 and
Excel 97. If you use an earlier version of Excel, you’re reading the wrong book. ... know to learn VBA. In this part, I introduce you to VBA, provide program-
ming fundamentals, and detail how to develop VBA subroutines and functions.
Chapter 11 contains tons of useful VBA examples.
Part...
... an invisible instance of Excel (not recommended).
/m Forces Excel to create a new workbook that contains a single Microsoft
Excel 4.0 macro sheet (obsolete).
/o Causes Excel to register itself ... to contend with.
Excel 5, which introduced VBA, represented a major paradigm shift for Excel developers.
Thousands of people up until that point earned their living developing Excel applications
that ... thinking.
Bugs? In Excel?
You might think that a product like Excel, which is used by millions of people throughout
the world, would be relatively free of bugs. Think again, pal. Excel is such a...
... 7
4799-2 ch07.F 6/11/01 9:29 AM Page 167
179
Chapter 8 ✦ VBAProgramming Fundamentals
Entering VBA Code
VBA code, which resides in a VBA module, consists of instructions. The accepted practice ... ✦ VBAProgramming Fundamentals
similar (or identical) to Excel s worksheet functions. For example, the VBA function
UCase, which converts a string argument to uppercase, is equivalent to the Excel
worksheet ... February 29, 1900, Excel accepts the following for-
mula and displays the result as the 29th day of February, 1900:
=Date(1900,2,29)
VBA does not have this date bug. The VBA equivalent of Excel s
DATE...
... function in Excel or
VBA to do the trick. But knowing how to access the Windows API may solve your
problem.
Detecting the Shift key
Here’s another example: Suppose you’ve written a VBA macro that ... If that’s not
enough, however, you can create custom functions by using VBA.
With all the functions available in Excel and VBA, you may wonder why you would
ever need to create new functions. The ... a VBA array
VBA includes a useful function called Array. The Array function returns a variant
that contains an array (that is, multiple values). If you’re familiar with array formu-
las in Excel, ...
... property. In this case, the code uses Excel s default file
path as the starting directory.
Displaying Excel s Built-In Dialog Boxes
Code that you write in VBA can execute Excel s menu commands. And, if ... with Excel
5 and Excel 95).
✦ Control Toolbox toolbar. These are ActiveX controls. These controls are a subset of
those that are available for use on UserForms. These controls work only with Excel
97 ... statements will work only in English language ver-
sions of Excel. For applications that will be used with other language versions of
Excel, you can use the FindControl method, along with the Id...
... into
utilities.
Using VBA to Develop Utilities
When I received the beta version of Excel 5, I was blown away by VBA s potential.
VBA was light-years ahead of Excel s powerful XLM macro language, and it made
Excel ... Developing Excel Utilities with VBA
Figure 16-10: The author’s Power Utility Pak contains many useful Excel utilities.
Summary
In this chapter, I discussed why you might want to develop Excel utilities ... to a finished product.
✦ VBA enables you to extend Excel in a way that is entirely consistent with
Excel s look and feel, including menus, toolbars, and dialog boxes.
✦ Excel can do almost anything....
... not execute.
Caution
Cross-
Reference
Programming Events in Older Versions of Excel
Versions of Excel prior to Office 97 also supported events, but the programming techniques
required to take ... of the con-
cept of Excel events, and I include many examples that you
can adapt to your own needs. As you’ll see, understanding
events can give your Excel applications a powerful edge.
19
19
CHAPTER
✦✦✦✦
In ... worksheet.
Excel is capable of monitoring a wide variety of events, and
executing your VBA code when a particular event occurs.
Following are just a few examples of the types of events that
Excel...
... instead of last).
Moving Up from Excel 5/95?
If you’ve customized menus using Excel 5 or Excel 95, you can pretty much forget every-
thing you ever learned. Beginning with Excel 97, menu customization ... and make it free- floating.
23
23
CHAPTER
✦✦✦✦
In This Chapter
An overview of
Excel s menu system
Types of menu
modifications you
can make
How to manipulate
menus with VBA
Various menu
programming
techniques ... There is no easy way to assign a VBA macro to a new menu item on the Tools
menu. This was a piece of cake with Excel 5/95. Later in this chapter, however, I pro-
vide VBA code that you can use to...
... Formats
Excel version Constant Value
Excel 2.1 xlExcel2 16
Excel 3.0 xlExcel3 29
Excel 4.0 xlExcel4Workbook 35
Excel 5 xlExcel5 39
Excel 95/97 xlExcel9795 43
Excel in HTML format xlHtml 44
Excel ... compatibility with
Excel 95, Excel 97, and Excel 2000, you should use Excel 95 for development, and
then test thoroughly using the other versions.
If your application must support Excel 95, you can’t ... For example, Excel 97,
Excel 2000, Excel 2002, and Excel 98 for Macintosh all use the
same file format — but compatibility issues are rampant. Just
because a particular version of Excel can open...
... A-1
Microsoft.com’s Excel- Related Newsgroups
Newsgroup Topic
microsoft.public. ProgrammingExcel with VBA or XLM macros
excel. programming
microsoft.public. Converting 1-2-3 or Quattro Pro sheets into Excel ... Examples. Excel workbooks that I discuss in
this book.
✦ Power Utility Pak. The trial version of my popular Excel
add-in. Use the coupon in this book to order the full ver-
sion free. The complete VBA ... the
information in this book applies to Excel 5/95 dialog sheets.
Add-Ins
Where can I get Excel add-ins?
You can get Excel add-ins from a number of places:
✦ Excel includes several add-ins you can...