Go to previous article
Go to next article
Return to 2004 Table of Contents
Cantor + Associates Inc.
When a person with a disability finds it inefficient, difficult, or impossible to perform a software task, the application itself can sometimes be tailored to meet the needs of the individual. Application customization is an indispensable technique for repairing accessibility problems and enhancing usability. The benefits of application customization for persons with disabilities include increased efficiency, reduced physical and mental effort, fewer errors, and greater user satisfaction.
In this paper I outline customization techniques that involve Visual Basic for Applications (VBA). VBA is a programming environment built into all Microsoft Office programs. It can be used to sculpt enhancements in Word, Excel, PowerPoint, Outlook, and Access.
Underlying all Microsoft Office applications are objects. Objects are its fundamental building blocks. Almost everything you do in an Office program involves manipulating objects. Each document, worksheet, dialog box, or range of text is an object that can be controlled programmatically in Visual Basic.
All applications consist of content and functionality. Content refers to words, numbers, or graphics. Content also refers to attributes or properties, such as the size of a window, the typeface of a word, or the thickness of a line. Functionality refers to the ways you can work with content, such as opening, closing, copying, deleting, pasting, or formatting. All objects are constructed of discrete units of related content and functionality.
The objects that make up an application are arranged hierarchically. The way that content and functionality are organized is called the object model. The content and functionality of applications are divided among the objects in the object model.
A property is a characteristic of an object, such as its colour, size or caption. You set a property to specify a characteristic or behaviour of an object. A method is as a way to access the functionality of an object. In general, properties act on content, and methods act on functionality.
There are two ways to interact with objects: manually, using the User Interface (UI); or programmatically, using VBA. In the UI, you use the keyboard or mouse, or both, to navigate to the part of the application that controls the data you want to change or the commands you want to use. For every action you take in the UI, there is a Visual Basic equivalent. In Visual Basic statements, you navigate through the object model from the top-level object to the object that contains the content and functionality you want to manipulate.
Before starting to program in VBA, become familiar with preexisting commands. Built-in commands appear as UI menu items and toolbar icons. For example, "FileOpen" is the Word command that appears in the "File" menu as "Open...," and as an icon on the "Standard" toolbar. The "FileOpen" command can also be invoked by pressing Ctrl+O or Ctrl+F12.
Many built-in commands do not appear in menus or on toolbars, and do not have keyboard equivalents. Of the approximately 1200 Word commands, the majority are not available by default. Before creating new commands, check for existing commands that do the same thing. Here are techniques for exploring built-in commands:
To examine built-in commands, launch the application, choose "Tools|Customize," and select the "Commands" tab. Lists of commands are organized by category, i.e., by menu or function. Word includes supplementary categories including "Fonts," "Styles,"" and "All Commands." The "All Commands" list is especially useful because it shows actual command names. In other categories, "colloquial" command names are given instead, i.e., the text that appears in menus or as toolbar icon labels. For example, "Close" is the colloquial name for "FileClose" command.
Use the "ListCommands" command to generate a table of Word commands and their key, menu, and toolbar assignments. The table lists colloquial command names, hotkeys, and the menu name or toolbar number on which commands appear.
Use the "ToolsCustomizeKeyboardShortcut" command to identify actual names of menu, toolbar, and keyboard commands in Word.
Use the macro recorder to show how actions performed in the UI translate into Visual Basic instructions. Checking the code will reveal which objects, properties, and methods are needed to perform tasks.
The macro recorder has limitations. You cannot record instructions to select text with a mouse, but you can record instructions to select text by keyboard. Another limitation is that you may not be able to capture exactly what you intend unless you edit Visual Basic instructions.
It is normal for recorded macros to fail under certain circumstances. One of the best ways to learn Visual Basic is to repair recorded macros that almost work.
A recorded macro often fails because it contains superfluous code. Macros created with the recorder usually contain unneeded instructions. Strip away extraneous code so that the macro does exactly what you intended, and nothing more.
VBA has features to assist in learning the language. These include:
Position the insertion point within a property or method, or select it, and press F1. This will bring up a help screen with code samples.
This feature displays a list containing code that would logically complete the statement at the current insertion point. Activate by pressing Ctrl+spacebar.
When this feature is enabled, information about functions and their parameters displays as you type.
To run a macro within VBA, position the insertion point anywhere within the body of the macro and press F5. To run it line-by-line, press F8.
Press F2 to obtain information about objects, properties, methods, events, and built-in constants.
After you have discovered built-in commands or created your own, incorporate the commands into the UI. (Note: only the third technique is keyboard and screen reader accessible.)
Mastering VBA takes considerable time and effort, yet the payback is significant. When a software feature is hard to use, difficult to learn, or not accessible to a person with a disability, assistive technology professionals have two recourses: report the problem and hope for an eventual bug fix; or craft a solution that eliminates or minimizes the problem immediately.
No Author. Microsoft Office 97 Visual Basic Programmer's Guild. Microsoft Press. 1997.
Alan Cantor. Enhancing the Accessibility of Word 97 Using Built-in Commands, Macros and Visual Basic Procedures. Handout for pre-conference course at RESNA 1999, Long Beach, CA.