Macro of the Month – October 2024 – CopyToListAlphaMenu
Copies a term to the chosen section of your style sheet in alphabetical order
last updated: 12/12/2024
Over the past year, the newsletter has featured two macros that seamlessly add words to your style sheet: CopyToList and CopyToListAlphabetic. This month’s macro offers a more powerful option for complex style sheets, allowing you to quickly populate multiple word list sections from a single menu.
CopyToListAlphaMenu
The story of CopyToListAlphaMenu begins with CopyToList. This macro adds terms to your style sheet but places them wherever the cursor is located—not ideal for organization. An editor asked Paul Beverley if the macro could be more functional, which led to the development of CopyToListAlphabetic. This enhanced version copies terms to the word list section of your style sheet, placing them in alphabetical order—a remarkable improvement. Whenever I demonstrate CopyToListAlphabetic, the excitement is palpable. It makes sense: Manually adding a word to a style sheet not only takes time to copy and paste but also requires you to reorient yourself back into the flow of editing. Because CopyToListAlphabetic works in the background, your focus on editing remains uninterrupted.
Now another editor has suggested an enhancement: What if you could add terms to different sections of a style sheet by choosing from a menu? When you run CopyToListAlphaMenu, a pop-up menu lets you select the destination section. This feature is ideal for projects with style sheets that contain multiple word lists, such as people's names, place names, and spelling preferences.
How It Works
To add a word to your style sheet, simply select the word (or for single words, click the cursor inside the word) and run CopyToListAlphaMenu. In the pop-up menu, type the number corresponding to the section of your style sheet where the term should be copied. The macro then pastes the word into the selected section in alphabetical order.
The macro handles all background tasks—copying, navigating to the correct section, and maintaining alphabetical order—allowing you to stay focused on editing.
If the selected term is already in the style sheet, the macro will beep; it doesn’t add the term a second time.
Basic Setup and Usage
Before you can use CopyToListAlphaMenu for a new project, you need to set up your style sheet file name (so the macro knows which document is the style sheet) and the section headings (so the macro knows where to place different types of terms). Follow these steps:
Include the word “sheet” in the file name for your style sheet (e.g., style_sheet_project.docx)
Create three sections in your style sheet using these exact terms (including capitalization) for the headers and format them as Heading 3:
Word list
Places
People
To use the macro:
Keep your style sheet open (it can be on a second screen or in the background)
In your working document:
To add a single word: Place your cursor anywhere in the word.
To add a hyphenated term: place the cursor inside the first word.
To add a multi-word term: Select the entire term, or roughly select it by clicking inside the first word, holding down the Shift key, and clicking inside the last word.
Run CopyToListAlphaMenu
In the pop-up menu, select the number corresponding to the desired section of the style sheet and press the OK button:
Type 9 for Word list
Type 6 for Places
Type 3 for People
(You can assign any keys to the selections (see below). Paul chose these numbers because they are near his mouse hand on a numeric keypad.)
Note, if the word you’re adding contains Track Changes markings, it will paste it into your style sheet with the tracking accepted.
Download the code: www.wordmacrotools.com/macros/C/CopyToListAlphaMenu
Customizing the Macro
The default settings work well for many projects. However, once you're comfortable with the basic functionality, you can customize various aspects to match your workflow.
1. Use a different identifier for the file name
To use a word other than "sheet" in your file name (e.g., style_guide_project.docx), replace the word “sheet” in the keyWord line of code, such as with “guide,” as shown below, retaining the quotation marks.
keyWord = "guide"
2. Customize section names
To use different titles for your word list sections, such as Characters, Locations, and Spelling Preferences, insert those names in place of “Word list,” “Places,” and “People” in the 10th–12th lines of code as shown in the example below. Make sure to match the exact capitalization in your style sheet and retain the quotation marks.
myList(1) = "9 Characters"
myList(2) = "6 Locations"
myList(3) = "3 Spelling Preferences"
numLists = 3
3. Add more sections
To add additional sections, add new myList lines for each section and update the numLists value to match your total. In the example below, I added a fourth list by inserting myList(4) = "1 Miscellaneous" and changing numLists = 3 to numLists = 4.
myList(1) = "9 Characters"
myList(2) = "6 Locations"
myList(3) = "3 Spelling Preferences"
myList(4) = "1 Miscellaneous"
numLists = 4
4. Change menu numbers
To use different indicators, such as letters instead of numbers, replace 9, 6, 3, and 1 with your desired indicators. In the example below, I used lowercase letters instead.
myList(1) = "c Characters"
myList(2) = "l Locations"
myList(3) = "s Spelling Preferences"
myList(4) = "m Miscellaneous"
numLists = 4
5. Change the default heading style
To use a different style for section headers, replace "Heading 3" in the myStyle line with your preferred style name, such as Heading 2, as shown below, retaining the quotation marks.
myStyle = "Heading 2"
6. Preserve the text formatting
To retain the formatting of the words, such as italics and bold, add an apostrophe in front of the includeFormatting = False line and delete the one from the beginning of the includeFormatting = True line as shown below.
' includeFormatting = False
includeFormatting = True
7. Silence the beep
When a word is already in your style sheet, the macro will beep when you run it to tell you. You can silence it by changing beepIfAlreadyListed = True to beepIfAlreadyListed = False as shown below.
beepIfAlreadyListed = False
Related macros
If you are already comfortable using CopyToListAlphabetic, you can manage multiple word lists using it by creating a new version of the macro for each list. This method allows you to use separate keyboard shortcuts for each section instead of selecting from a menu. For details about this alternative approach, see the March 2024 newsletter.
Video demonstration of CopyToListAlphaMenu and how to customize CopyToListAlphabetic: www.youtube.com/watch?v=RDqBw0zy4kI
Ready to Try It?
If you manage style sheets with multiple sections, this macro could transform how you organize terms across different categories. Test it on a copy of your current style sheet using the three preset section headings (Names, Places, and Word list) to get comfortable with the menu system. Once you see how it works, you can add more sections and customize the labels to match your needs. For style sheets with a single word list section, CopyToListAlphabetic is the more efficient choice.
Questions? Comments?
Have you recently discovered a macro you’d like to share with other editors? Do you have a question about this macro or others? Please comment on this post.
Happy macroing,
Jennifer
One downside to CopyToListAlphaMenu is that in the style sheet, the list of personal names will be alphabetized by given name rather than surname. One solution is to run the SurnameSorter macro on that list once it's complete.