Windows Macros FAQ
Version 5Copyright © Alan Cantor 2005 - 2020. All rights reserved.
- What is a macro?
- Why write macros?
- What macro applications are available?
- Are macro development tools easy to use?
- Are macro applications screen reader accessible?
- How are macros created?
- How are macros activated?
- What skills and knowledge do I need to write macros?
- What is a global hotkey?
- What keys can be assigned?
- How do I create global hotkeys
- How can I remember my global hotkeys?
Welcome to the Windows Macros FAQ. This resource is for people who want to operate Windows® more efficiently by taking advantage of macro software and macro techniques.
Running Windows® without macros is like cycling through the mountains on a fixed-gear bicycle. It can be done, but it is unnecessarily difficult. Think of macros as gears for your computer. Macros reduce physical and mental effort while multiplying speed and increasing efficiency.
This FAQ has four main sections. Fundamentals answers basic questions about macros. Smart Macros introduces the topic of macros with built-in intelligence. A smart macro acts on the basis of information received both from the user and from the user interface, and provides elegant, reliable, and seamless fixes to otherwise intractable accessibility and usability problems. The global hotkey section describes a standard Windows® technique for opening files, web pages, and folders, and for launching applications. The fourth section discusses two application-specific macro techniques: code replacement shortcuts and built-in macro languages.
This is a work-in-progress. Bookmark this page and check back often. Your feedback and questions are welcome.
What is a macro?
A macro is a software shortcut for performing a series of steps or commands as a single task. Tasks may be simple, such as inserting a word; or complex, such as copying data from one program and pasting it in another. More sophisticated macros actively and passively collect information from the user and from the user interface, and make decisions on the basis of this new data.
Examples of tasks that can be performed using macros:
- Insert one's name, address, e-mail address, or signature file.
- Insert symbols and foreign characters.
- Insert the date and time.
- Abbreviate words or expressions.
- Launch or switch to a program.
- Open a file or web page.
- Close, resize, or move a window.
- Adjust the speaker volume.
- Detect a program, window, or control.
- Detect the state of a window, control, mouse pointer, or point on the screen.
- Copy data from one application and paste it in another.
- Display a dialog box and prompt the user to enter information or confirm an action before proceeding to the next step.
- Click on an object that is not keyboard accessible.
- Combinations of the above.
Why write macros?
Macros save time, energy, and frustration. Macros automate repetitive, awkward, physically-demanding and mentally-taxing tasks. In addition, accessibility and usability problems can sometimes be fixed with macros.
What macro applications are available?
Macro applications come in two "flavours:" those that act on programs from the inside; and those that act on programs from the outside.
“Insider” vs. “Outsider” macro applications
Programming languages built into existing programs, such as Visual Basic for Applications (VBA) for Microsoft Office products, and PerfectScript for Corel products, do their work from the inside. Once created, the macros reside within and are integrated into the programs for which they are written. For example, VBA commands for Microsoft Word are stored in a binary file called Normal.dot. The commands and macros contained in this file load automatically each time Word is launched.
"Outsider" macro applications are third-party scripting utilities. The macros that these tools produce reside in the macro application itself (or in executables that the macro application generates). The macros are "outsiders" in the sense that the macro software is distinct from the programs it affects, and its macros act upon other programs — usually by sending keystrokes and/or controlling the mouse pointer.
Examples of full-featured Windows®-based macro scripting tools:
Other macro packages:
The macros produced by built-in programming languages tend to be more portable than those produced by third-party scripting tools. Whereas VBA macros should, in theory, work equally well on all computers, "outsider" macros may need tweaking — and sometimes rewriting — to work on another PC.
As a general rule, "insider" macros are more reliable than "outsider" macros, and "outsider" macros are more versatile than "insider" macros. A skilled developer knows how to make "insider" macros versatile, and "outsider" macros reliable.
Are macro development tools easy to use?
Macro Express is powerful and easy to use. Keyboard Express, which is made by the same company, lacks many features included in Macro Express. ActiveWords is fairly easy to use, but lacks features found in Macro Express. AutoHotkey is very powerful but lacks a user interface to simplify macro creation; the learning curve is steep. Macro Scheduler is less versatile than either AutoHotkey and Macro Express. It is easier to learn than AutoHotkey, but harder to use than Macro Express.
VBA is a full-blown programming environment for controlling and interacting with an application's "objects." Learning to manipulate objects may be challenging for those without experience with other object-oriented programming languages. VBA is probably harder to learn than PerfectScript.
Are macro applications screen-reader accessible?
Full-featured screen readers have built-in macro scripting languages. The macro-writing tools in JAWS and Window-Eyes have been optimized for screen reader access, and work elegantly with speech.
Some software access problems are best resolved by scripting speech-friendly macros with third-party scripting tools. But because screen readers and macro applications both intercept input from the keyboard, conflicts can arise. The following compatibility information is based on reports from screen reader users:
Macro Express 3.x menus are difficult to access with JAWS, but it is possible. Set "Menu style" to "Flat" to improve screen reader access. (Options menu, Preferences...) Menus are easily accessed with Window-Eyes.
Overall, the Macro Express user interface is not particularly speech-friendly. Dialog boxes are fairly accessible, but some controls have non-standard behaviour, such as the list of hotkeys when choosing an activation method. It is possible to Tab to the list of hotkeys, but navigating backwards from the list causes Shift+Tab to be selected as the hotkey. Some wizards work better than others with speech, but most cannot be accessed without using the roving cursor.
Macro Express macros can be activated when JAWS is running, but not when Window-Eyes is running. I have seen people using Window-Eyes to script macros, and JAWS to test and run them.
Not yet tested with JAWS. ActiveWords does not appear to conflict with Window-Eyes.
Very easy to access because macros can be written in any text editor. The downside is that there is no user interface to simplify macro creation. No screen reader compatibility problems for activation have been reported.
No screen reader compatibility problems have been reported for JAWS or Window-Eyes.
Visual Basic for Applications
VBA is fairly screen reader accessible, although some features are difficult or impossible to access with speech. Nevertheless, I have met developers with visual impairments who code in VBA via screen reader.
How are macros created?
There are four main macro creation techniques:
Capture (Macro recorder)
Record command sequences by typing, pressing hotkeys, and manipulating the mouse. The technique works best for simple tasks; it is less reliable for complex ones. Some macro recorders capture mouse movements, and others do not. Captured mouse movements are notoriously unreliable when replayed. VBA's macro recorder ignores many (but not all) mouse movements, but it does reliably record the same actions when performed by keyboard.
A wizard guides the user through a series of questions, and automatically generates a script. Macros created in this way work best for simple tasks.
Type or insert commands directly into a macro editor. This technique is very powerful, but may require programming experience.
Select, insert, and edit commands via a user interface to build a script. This technique is adequate for crafting all but the most complex macros.
How are macros activated?
There are at least 13 different macro triggers. The six main ones are:
To activate a hotkey macro, the user presses a key or a key combination. There are two kinds of hotkey macros:
- A single-key hotkey executes after pressing a single key or key combination. For example, launch an e-mail program by pressing Ctrl+E.
- A dead-key hotkey executes after pressing a sequence of two keys. Nothing appears on the screen when the first key is pressed; the macro activates only after the second key is pressed. For example, in some applications, pressing Ctrl+/ followed by O inserts Ø.
Code macros are triggered by typing text. The macro runs when a specific sequence of characters has been entered. There are two kinds of code macros:
- Suffix macros are triggered by typing a code followed by Spacebar, Enter, and punctuation characters ("suffix keys"). For example, typing TEL followed by a suffix key inserts your telephone number; WP followed by a space launches a word processor; and SIG followed by a space, punctuation mark, or Enter inserts a signature file.
- Prefix macros are activated by typing a user-selected prefix followed by a code. For example, if J is the prefix, entering JTEL types a telephone number; JWP launches a word processor; and JSIG inserts a signature file.
When code macros execute, the code and the prefix/suffix are usually deleted. The macro may have untoward effects if pressing Backspace does something other than delete characters. In Internet Explorer, for example, pressing Backspace goes "Back" to the previous web page (unless an edit box has keyboard input focus.)
Timed macros activate at specific times, at set intervals, or after certain delays. They are used to run programs at set intervals, display timed reminders, and regulate the timing in multi-step macros. For example, when writing a macro to copy the URL of a web page and paste it in NotePad, it may be necessary to wait for NotePad to appear before issuing the "Paste" command. The macro might consist of five steps:
- Go to the Address line and select it. (In Mozilla Firefox or Internet Explorer, press Alt+D.)
- Copy to the clipboard.
- Switch to Notepad.
- Wait 2 seconds.
Macros execute very quickly. Without a "Wait" command, this macro may issue the paste command before Notepad gains focus.
Event macros execute when specified programs, windows, or controls gain or lose focus. Event macros are needed to regulate complex command sequences. The previous example will be more reliable if the "Paste" command is triggered by the appearance of NotePad (an event) rather than the passage of a fixed number of seconds:
- Go to the Address line and select it.
- Copy to the clipboard.
- Switch to Notepad.
- Wait until Notepad has focus.
Mouse macros are activated by clicking on specific areas of the screen; on user-defined menus or icons; or simply by clicking anywhere on the screen. For the latter type, it is usually necessary to hold down one or more modifier keys. Macros can also be activated by clicking the middle mouse button.
Products like NaturallySpeaking and Microsoft Speech Recognition allow users to create custom commands. For example, a command that is invoked by saying "My Telephone Number" inserts a telephone number.
What skills and knowledge do I need to write macros?
Scripting tools such as Macro Express and ActiveWords have steep learning curves, although adventurous novices who persevere will likely have success. AutoHotkey is closer to a programming language than a scripting tool, and may be harder for beginners to learn. On the other hand, its excellent help system contains many code samples that can be copied and pasted.
Macros for automating complex series of steps require intermediate- or advanced-level understanding of Windows® as well as good knowledge of the macro creation tool. A superior understanding of the keyboard interface is essential; macros that move the mouse pointer and click are unreliable. When writing smart macros, rudimentary programming experience is helpful, but not essential.
No special skills are needed to create very basic VBA macros because the macro recorder automatically generates the code. But to capture more than a few simple commands, you must work in the VBA editor and become familiar with the application's "objects" and "object model." If you lack an understanding of objects, you will gain it by the time your first macros are debugged!
What is a smart macro?
I coined the term "smart" (or "intelligent") macro in 2005 to describe a computer shortcut that is activated either by the user or the user interface (UI), and performs tasks based on feedback that the macro receives from the user, the UI, or both. A smart macro mediates between the user and the computer, makes decisions, and acts on the basis of information it receives from two sources. In contrast, a "dumb" macro is always activated by the user, cannot be controlled once it has been activated (except, perhaps, to halt its execution), and neither detects nor acts upon information from the UI.
Smart macros have a modicum of built-in intelligence. This intelligence increases their flexibility, reliability, and accuracy. Well-designed smart macros dramatically improve software accessibility and usability in ways that cannot be achieved by other means — other than repairing the source code. A smart macro may be so seamless that users may not realize they are interacting with a macro. For smart macros that are triggered automatically or that workaround programming errors, there may be nothing new for users to learn or memorize. Smart macros simplify access to information because the macros themselves assume some of the physical and cognitive effort required to drive software.
What are smart macros used for?
Macros with built-in intelligence have four main uses:
1. Repair accessibility problems
A repair macro fixes an accessibility problem, usually within a specific window or program. For example, the "Options" dialog box contains a text field labelled "Address" (with underlined accelerator "A"), but pressing Alt+A does not move focus to the field. The repair macro, triggered by Alt+A, moves the focus to the text field by sending keystrokes, moving and clicking the mouse, or a combination of the two. This hotkey is available only when the titlebar says "Options," so Alt+A works normally in other windows.
2. Fix usability problems
A macro that fixes a usability problem forces a non-standard application to work the ways that users expect. If, for example, "Save" is F2 instead of Ctrl+S, a program-specific macro can be written to send F2 to the application when the user presses Ctrl+S. Because the macro is program-specific, the hotkey has no effect on other applications.
3. Regulate complex tasks
When automating a task to perform a series of actions, a dumb macro may play back faster than the computer can keep up. The only technique for a dumb macro to control information flow is to pause at critical moments. Macros with time delays tend to be unreliable because pause lengths vary and are unpredictable. This is especially true when a macro interacts with the Internet; network bottlenecks can easily throw off the timing of scripts that are regulated with time delays.
The smart macro's ability to process information from the UI allows for more reliable control. Rather than wait for preset time periods, a smart macro waits for specific events to occur, and tests that the events have occurred before continuing. Events that can be monitored include:
- A window gains (or loses) focus.
- A web page finishes loading.
- The mouse cursor changes shape.
- A control becomes visible, gains focus, or is enabled.
- A file or folder comes into existence.
- A specific pixel changes colour.
Testing for UI changes makes it possible to detect errors. For example, if a particular window does not appear within 10 seconds, the macro can stop, prompt the user for further instructions, or wait longer.
4. Activate automatically
An automatic macro activates when a specific change occurs in the user interface. Many of the events listed above can serve as triggers. Automatic macros can also activate at set times or at regular intervals.
How do I create smart macros?
Choose any macro software product that supports these four features:
- Scope, i.e., macros that work only in certain windows or programs.
- Conditional statements, e.g., IF - THEN - ELSE.
- Event triggers, e.g., macros that recognize when windows or controls gain or lose focus, a specific pixel changes colour, or the mouse pointer changes shape.
What is a global hotkey?
Windows® allows users to assign about 400 hotkeys for launching applications, opening files and web pages, and opening folders (such as "Recycle Bin," "My Computer," "Control Panel," and "c:\Windows\Desktop"). These hotkeys can be activated at any time, in any program, in any context. They are usually referred to as "desktop shortcuts," but because these shortcuts are always available, I refer to them as "global hotkeys."
When a global hotkey and an application-specific hotkey conflict, the global hotkey takes precedence.
What keys can be assigned?
Most global hotkeys consist of two or three modifier keys (Shift, Ctrl and Alt) plus one other key. Examples of keys that can be assigned include:
- F2 through F12. Note: F11 and F12 do not appear to be available in Windows 2000 and XP.
The following keys cannot form part of a global hotkey:
- Print Screen
How do I create global hotkeys?
Follow this procedure to make global hotkeys:
- Locate the icon of an application, folder or file. Note: To make global hotkeys for Microsoft Office products, you will need to find each program's executable: winword.exe, excel.exe, outlook.exe, and so on.
- Create a shortcut.
- Move the shortcut icon to the desktop.
- Select the desktop icon.
- Invoke its "Properties" page.
- Go to the "Shortcut" tab.
- Go to the "Shortcut key" edit box.
- Press the desired key or key combination.
- Press Enter (or click the "OK" button).
The shortcuts do not have be on the desktop. They will work if they are placed in certain folders, but not in others. Shortcuts can be stored in "Start menu | Program Files | Shortcuts."
How can I remember my global hotkeys?
Global hotkeys become second-nature with practice. To help internalize the keystrokes:
- Always use the same modifier combination for all global hotkeys. For example, make every hotkey Ctrl+Alt+... or Shift+Ctrl+...
- Jot hotkeys on Post-it notes and stick them on the monitor.
- Rename desktop icons to include the hotkey, e.g., Shift+Alt+Word and Shift+Alt+eXcel.
- Invent striking mental associations, e.g., "My alternative, nifty-shifty home page that I control is Alt+Shift+Ctrl+Home."
What are code replacement shortcuts?
Code replacement shortcuts insert information as you type. The code can be a word, a nonsense word, a number, a phrase, or a series of letters, numbers, and/or non-alpha-numeric characters. After typing the code, the shortcut is activated by pressing Spacebar, Enter, or a punctuation character.
Both Word and WordPerfect have code replacement features, AutoCorrect and QuickCorrect, respectively. Of the two, AutoCorrect is more versatile. QuickCorrect handles plain text and some formatted text; AutoCorrect handles plain text, most formatted text, images, tables, updatable fields, and more. Some (although not all) AutoCorrect features function in other Microsoft Office products. A code replacement shortcut added to Word usually will work in Excel and PowerPoint.
Code replacement is a boon to anyone for whom typing is difficult or awkward, including individuals with upper-body mobility impairments, and people with learning disabilities that affect hand-eye coordination and/or the ability to spell. People with low-vision also benefit because code replacement shortcuts reduce eye-strain. For example, the normal way to insert a symbol into a Microsoft Word document is visually intensive: navigate via a menu to a dialog box, choose the font and a font subset from drop-down lists, find the symbol, select it from an 8-by-24 cell grid, and click the "Insert" button. By creating, say, a two- or three-character code replacement shortcut for the symbol, eye-strain is eliminated.
There are many creative ways for improving computer access with code replacement shortcuts. The following descriptions and chart illustrate five different techniques:
1. Correct misspelled words
This technique works well with people with learning disabilities, and other individuals who, for whatever reason, frequently mistype certain words.
2. Abbreviate words and phrases
Rather than repeatedly type long words and expressions, substitute short codes.
3. Insert symbols and foreign characters
Simplify the insertion of the foreign characters and symbols you use regularly.
4. Repair capitalization
Eliminate the need to press the Shift-key when entering acronyms, words with unusual capitalization, and words and phrases containing alternate "upper" characters such as ! and @.
5. Insert images and formatted text
Enter chemical formulas like H2O and mathematical expressions such as ex on the fly. Use the same technique to insert images, tables, tables of contents, and fields.
|Correct misspelled words||untill||until|
|Abbreviate words and phrases||px||peroxide|
|sss||Sandy S. Smith|
|myletter||Thank you for your recent letter.
Sandy S. Smith
|Insert foreign characters and symbols||e/||é|
|Insert formatted text and images||h2so4||H2SO4|
|ourlogo||White, Black and Clear Attorneys
25 Grace St., Suite 200, York
What about built-in macro languages?
Some applications have built-in programming interfaces. The programming language for Office, Visual Basic for Applications (VBA) is a subset of the Visual Basic (VB) programming platform. Whereas VB is designed to create stand-alone applications, VBA is designed to customize existing applications. Both VBA and VB are Microsoft products.
The built-in macro language for Corel applications is PerfectScript. Beginning in 1999, however, Corel has licensed Microsoft VBA for use with WordPerfect and several other Corel products. PerfectScript continues to be supported as a macro language for Corel products.
VBA can be used to build custom commands, repair accessibility problems, and develop usability enhancements in word processors, spreadsheets, database managers, e-mail applications, and presentation software. Not all programs offer VBA support. For example, VBA works with Outlook, but not Outlook Express. The application with the best VBA support is Microsoft Word.
Recording vs. authoring Word macros
There are two ways to create Word macros. Capture them using the macro recorder, or enter them directly in Visual Basic for Applications. The recorder cannot capture certain mouse movements (e.g., text selection via mouse), and recorded macros tend to replay slowly. They are also somewhat unreliable.
Macros coded directly in VBA, however, execute quickly and can be made extremely robust. A good way to learn VBA is the hybrid approach: record macros, and then study and edit the code. The VBA help system is excellent, and contains code fragments that can be copied and incorporated into new commands.
- Choose a task to perform in Word. Before beginning, ensure that you know exactly how to perform the task. If a task involves selecting text, you must use keyboard commands.
- Start recording. Select "Tools | Macro | Record New Macro..." Name the macro. Assign a keyboard or toolbar shortcut.
- Record the macro. Perform the task without making mistakes.
- Stop recording. Click the "Stop" button on the "Stop Recording" toolbar, or select "Tools | Macro | Stop Recording."
- Test the macro.
- Study and refine the code. Press Alt+F11 to open the Visual Basic for Applications editor. Use the Help system to learn about the code and the structure of the language.
What are your questions?
Feel free to submit your questions. Any comments about this FAQ are welcome.
A special thank you to Jane Berliss-Vincent, Dean Martineau, Neville from Australia, Frank Ibarra, and Paul Makulski for their important contributions to this FAQ. I also thank the hundreds of people who have attended my lectures, hands-on workshops, and web-casts on macros and macro techniques. Your questions and comments have helped to refine my understanding of the usefulness and power of macros.
The information contained in this FAQ is intended as a guide only. It is current to the best of the author's knowledge, having been compiled from sources believed to be reliable. No warranty, guarantee, or representations are made by the author as to the absolute correctness or sufficiency of any representation contained in this FAQ.
Microsoft, Windows, Word, Excel, Outlook, Outlook Express, Notepad, Visual Basic, Visual Basic for Applications, and Internet Explorer are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.
"Windows Macros FAQ" is an independent publication and is not affiliated with, nor has it been authorized, sponsored, or otherwise approved by Microsoft Corporation.