Life in a Macro

by Jack Lyon

After mentioning my new Macro Cookbookover the course of several blog posts, Rich Adin has graciously asked me to write a guest editorial related to macros, something I’m delighted to do. In his most recent post, Rich described his technique for sketching out a flow chart on paper, which helps him outline what he wants a macro to achieve before he starts working on the macro itself. This time-honored technique for programming is clarifying and efficient, especially in the early stages of a macro:

As I read Rich’s post, however, I realized that it’s been many years since I created a flowchart before starting to make a macro. Why is that? I wondered. What’s changed? And what do I do differently now?

I think what’s changed is that I’m now a lot more focused on the outcome of a macro rather than its process. As my programming skills have improved, I’ve become more concerned with what rather than how, with ends rather than means because the ability to create those ends has become almost second nature. And I think most skills are like that.

I’m a moderately skilled jazz musician (Hammond organ with Leslie speaker — oh, yeah), but I still have lots to learn, and when I’m working on a new run, I have to play quite mechanically until finally my fingers learn where I want them to go. After that, I can use the run in a variety of songs. But a run isn’t a song. And it’s the song that’s important. The song is the run’s reason for being.

When I’m creating a macro, the first thing I do is decide precisely what I want the macro to do. Some examples:

Title case every paragraph styled as Heading 1.

Remove extra spaces between footnotes.

Convert an automatically numbered list into a manually numbered list.

After getting the purpose firmly in mind, I usually work on a simple macro to see if what I want to do is even possible (proof of concept). If I were trying to title case every paragraph styled as Heading 1, for example, my thinking might go something like this:

Okay, first I need to create a macro that finds a paragraph styled as Heading 1. Hmmm. Probably easiest just to record it.

So gradually I’ll put together the various macro commands that work in sequence to do what I need.

Easy for me to say, right? Okay, okay. If you’re just getting started with macros, using Rich’s flowchart is a better way to go. Decide precisely, step by step, the things you want your macro to do, and list those steps:

Find a paragraph styled as Heading 1.

Title-case the paragraph.

Repeat steps 1 and 2 until no more paragraphs are found.

Then get the commands for each step (by recording, borrowing, or whatever).

Then put the commands together to do what you need.

Finally, test your macro to see if it does what you planned. If it doesn’t, revise it until it does.

As this is the beginning of a new year, I’m feeling a little philosophical, so I’m wondering if we could apply a similar process to life. Can we figure out precisely what we want to have happen and then figure out the essential steps to make it so? Or is life more complex and unpredictable than that? Time to get out those flowcharts!

I hope this new year will be a happy one for you and yours.

__________________

It strikes me that Jack’s approach is to have a single focus and then to combine several single-focus macros into a single macro that runs serially. I may be wrong about his approach, but I do think it demonstrates how different the approaches to writing macros can be. Jack’s approach is also one that an experienced macro creator can use, but I think for those of us who are not at the mastery level, flow-charting is better because it helps us focus on the steps.