An American Editor

January 2, 2012

The Professional Editor: Working Effectively Online VII – Macros Again

In prior posts, I talked about how effective online editing includes mastering macros. See, for example, The Professional Editor: Working Effectively Online IV — Mastering Macros. What wasn’t discussed is how to plan a macro.

For the simple macro, the macro that, for example, replaces two spaces with one space, not much planning is required; what is needed is fairly obvious. As a macro grows more complex, however, the difference between success and failure is often how much effort was placed in the planning of the macro. A well-planned macro nearly writes itself.

Consider most of the macros in the EditTools collection. These are complex macros that require multiple routines to accomplish designated goals and tasks. Because of their complexity, it is easy to get lost in the programming and thus not produce a usable macro.

Consequently, when planning a macro I use a decision-tree process. I also use Storyboard paper that I buy from Levenger because it helps me visualize what I need to do. More importantly, it breaks what I need to do down into manageable chunks.

I begin at the end of the process: I define what I want the macro to accomplish. I then try to define each step that will take me to that endpoint. I use the If…Then… process: If abc is found, Then do xyz, but If abc is not found, Then do pqr.

Using the storyboard, I make each If…Then… its own entry. In the blank box on the left, I write the If…Then…; on the lines to the right, I write the code, line by line to make the If…Then… happen. It takes at least a pair of boxes to make a single whole If…Then… phrase because the first is the found and the second is the not found. Sometimes more than one not found is required so a single If…Then… process may need more than a pair of boxes.

Note, however, that I am using the If…Then… concept as a substitute for a lot of possibilities. It should not be taken literally as an If…Then… in coding terms. It is simply a way of breaking the process down into manageable chunks.

Making these small blocks of code serves many purposes. To make them reusable, I also number them. The numbers are not used except as a way to cross-reference. If I have already written a chunk of code that will do what I need done in the next step, I simply refer to the block of code by number for later copy and paste.

The small chunks also serve a much more important purpose: they make it easier to figure out why something is not occurring as I intend. Plus they can be reused in other future macros — no sense reinventing the macro. And they make it much easier to rearrange a macro’s coding when I subsequently think of a better or more efficient way to accomplish a task.

Yet I can hear the question now: Why do on paper what you need to do online? Yes, it can be repetitive work to first do the coding on paper and then transfer the coding to online, but the process allows me to think twice about what I am doing and — definitely of more importance — coding online takes away the storyboard decision-making tree, thus making it harder to visualize the entire process or even how a small portion fits within the scheme of the macro. A little extra work now often saves a lot of extra work later.

If you look at the Storyboard paper, you see the box at the left in which I place my decision-tree information. That information serves much the same purpose as inserting a comment into a macro. But on the Storyboard I can readily see what comes before and what comes after the block on which I am working, which can be difficult to do onscreen.

No matter what method you ultimately choose, you need to have a decision-tree method at hand so as to avoid missing important steps in the macro process or leaving out things you want the macro to do depending on what is found or not found. If you use or have available Microsoft PowerPoint (or a similar program), you can use it to create an onscreen storyboard. I have tried it, but found it too cumbersome for me; at heart, for these kinds of tasks, I’m still a creature of habit and my generation and paper and pencil seem to work best.

The key is, however, to plan your macro. Even if the coding is beyond your capabilities and so you intend to hire someone to code the macro for you, having a decision tree that can be given to the coder will reduce your costs and ensure that the coder understands what you want. The coder may have suggestions for improvement, but the decision tree ensures that everyone is on the same page.

The decision tree can also make your learning to code complex macros easier and quicker. Combine it with Jack Lyon’s Macro Cookbook for Microsoft Word, and you will discover that as you learn to code a small portion of a macro you are mastering macros. You will also find a greater sense of accomplishment as one coding success follows another in logical sequence.

The combination of the decision-tree process and the Macro Cookbook is a sure way to master the macro process a professional editor needs. Remember that the more efficiently you can edit the more money you can make over the long-term. The biggest failing professional editors have is the inability to get beyond the short-term outlook. Taking on the challenge of mastering macros will help you extend your outlook to the longer term.

April 21, 2010

It’s the Little Things: Software Redux

Not discussed in my previous articles was Microsoft Word’s built-in macro language, Visual Basic for Applications (VBA). But this resource is exceedingly valuable to an editor. Every editor should at least master using wild cards and should try to learn the fundamentals of writing “simple” VBA macros.

I edit a lot of very long manuscripts — 2,000 to 10,000+ manuscript pages — in the STM (science, technical, and medical) fields. It is not unusual for these manuscripts to have chapters with 300 to 1,500 references, and the one thing I can almost universally rely on is that the references are not in proper form, and are even inconsistent among themselves.

For example, a manuscript I am currently working on has a citation style that looks like this for a journal article:

Surname Initials, Surname Initials. Article title. Journal vol;page-page, year.

In one chapter with nearly 500 references, not a single reference was in that form. The style was all over the place and it is my job to fix it.

Fixing the problems means I can do each reference individually or I can identify patterns and write a macro or use wildcards with Find & Replace. For most editors, the easier solution is to use wildcards with F&R. Using F&R means breaking down the references into their parts. It isn’t possible — at least as far as I have been able to determine — to create a single macro or F&R routine to take care of all of the variations that the authors provide. Consequently, I try to address parts of the problem.

 For example, if the authors have put some of the citations in this form:

26, 1988, 1101-1105.

and I want to change it to this form:

26:1101-1105, 1988.

I make use of wildcards as follows:

Find: ([0-9]@)(, )([0-9]{4})(, )([0-9]@)(-)([0-9]@)(.)

Replace: \1:\5\6\7\4\3\8

Similarly, if the authors have really made it complex by using the citation form

2005, Dec;24(12):2037-042.

which I need to become

24(12):2037-042, 2005.

I use a 2-step wildcard F&R as follows:

1st Find: ([0-9]{4})(, [A-z]@;)

 1st Replace: \1;

 2nd Find: ([0-9]{4})(; @)([0-9]@[(][0-9]@[)]:[0-9]@-[0-9]@)(.)

 2nd Replace: \3, \1\4

Every time I figure out the wildcard F&R, I copy the parameters to a word document that I keep handy for the next chapter. This way I only have to copy and paste and click Replace All. I do have to go through several F&Rs, which will correct most — but not all — of the variations; but it is better to have 90% corrected automatically than to have to do them all manually.

And to address problems where, for example, the authors give the reference author names as AW Smith instead of Smith AW, I write a simple macro that I assign to my keyboard (and my XKeys) to make that reversal:

Sub ReverseAuthorName1()

‘ ReverseAuthorName1 Macro
‘ Macro created 4/7/2010 by Freelance Editorial Services

    Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
    Selection.Cut
    Selection.MoveRight Unit:=wdWord, Count:=1
    Selection.PasteAndFormat (wdPasteDefault)
End Sub

 As you can see, even a simple macro can make life easier and editing more productive. What do you do when an author has added punctuation following the journal name and there isn’t supposed to be any? For example, the author gives you

N Engl J Med. 1998;2:200-210

and the correct form for your client is

N Engl J Med 2:200-210, 1998?

We know how to move the year to the end globally but that doesn’t solve the problem of the punctuation following the journal name. You could modify your wildcard F&R but that won’t remove the punctuation where the rest of the cite doesn’t match the Find parameter. The answer is to write a macro.

Here is the macro I use. It works so I’ve not improved it as I’ve grown more knowledgable about VBA. This macro can be much more simply and efficiently written; it was one of my earliest attempts at macro writing.

Sub RefsRemovePuncAfterJournalName()

‘ Remove Punctuation After Journal Name in References Macro
‘ Macro created 10/7/2004 by Freelance Editorial Services

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = “/, ”
        .Replacement.Text = “/,Œ‰”
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = True
        .MatchWholeWord = False
        .MatchWildCards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    ‘ Replace [number],[space] with [number],[smiley]‰

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = “([0-9])[, ]”
        .Replacement.Text = “\1,” & ChrW(9786) & “‰”
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildCards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    ‘ Replace [space][number] with ¿‰[number]

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = ” ([0-9]{4})(;)”
        .Replacement.Text = “¿‰\1\2”
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildCards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    ‘ Replace ,¿ with [space]

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = “,¿”
        .Replacement.Text = ” ”
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = True
        .MatchWholeWord = False
        .MatchWildCards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    ‘ Replace .¿ with [space]

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = “.¿”
        .Replacement.Text = ” ”
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = True
        .MatchWholeWord = False
        .MatchWildCards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    ‘ Replace [smiley] with [space]

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = ChrW(9786)
        .Replacement.Text = ” ”
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = True
        .MatchWholeWord = False
        .MatchWildCards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    ‘ Replace ¿, Œ, and ‰ with [space]

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = “[¿Œ‰]”
        .Replacement.Text = ” ”
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildCards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = “([A-z]@)(.)(^32)([0-9]@{4})(;)”
        .Replacement.Text = “\1\3\4\5”
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildCards = True
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

    ‘ This section resets the wildcards to off

    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = ”  ”
        .Replacement.Text = ” ”
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = True
        .MatchWholeWord = False
        .MatchWildCards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = ”  ”
        .Replacement.Text = ” ”
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = True
        .MatchWholeWord = False
        .MatchWildCards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
   
End Sub

The macro looks more complex than it really is. The point is that you, too, can write these macros for your own needs if you make the effort to learn a little VBA. But even if you don’t want to go that far, you need to learn how to use wildcards. The time that wildcards and macros can save you puts money in your pocket. More importantly, it prevents the frustration you encounter when you face a lengthy reference list and discover that not one author-provided reference is in correct form.

I suggest picking up a book on VBA programming and also checking out the information on macros and wildcards found in Microsoft Word for Publishing Professionals by Jack Lyon (available at http://www.editorium.com and through bookstores via ISBN 9781434102362). Jack’s book is one of the best sources for introductory information on macro writing available.

Live, learn, and prosper!

Blog at WordPress.com.

%d bloggers like this: