An American Editor

June 9, 2014

Lyonizing Word: Formatting with Macros

Formatting with Macros

by Jack Lyon

Most users of Microsoft Word format text by selecting a paragraph and then applying a font. More advanced users apply a style. Why? Because then if they need to change the formatting of, say, level-2 headings, they can simply modify the style rather than tediously selecting each heading and applying a different font. (If you’re reading this, you’re probably one of those advanced users.) But there is a way to handle formatting that is even more powerful.

Suppose that you’ve dutifully applied styles to the various parts of a document, but then your client asks you to change the font—everywhere in the document—from Times New Roman to Adobe Garamond. You could manually modify each style, but if there are dozens of styles in use, there is a better way. That way is a macro, like this one:

Sub SetFontInAllStyles()
Dim aStyle As Style
For Each aStyle In ActiveDocument.Styles

aStyle.Font.Name = “Adobe Garamond”

Next
End Sub

Well, that was easy. Let’s look at each line of the macro (excluding the first and last lines, which simply define the beginning and end of the macro).

Dim aStyle As Style

That line dimensions (defines) a variable, aStyle, as a style. (As with all variables, I just made up the name “aStyle.”) At one point as the macro runs, aStyle might represent the style Heading 1. At another point it might represent Heading 3. But it will always represent a style.

For Each aStyle In ActiveDocument.Styles

Here’s where things get interesting. That line tells the macro to cycle through each style (represented by aStyle) in all of the styles in the active document (the document in which your cursor is currently sitting).

aStyle.Font.Name = “Adobe Garamond”

That line tells Word to set the font for the style currently being represented by aStyle to be Adobe Garamond.

Next

That line tells Word to go to the next style in the document.

When you run the macro, it will cycle through each style in the document (For Each…Next) and set Adobe Garamond as the font used in that style.

But what if you want to change the font only in heading styles (Heading 1, Heading 2, and so on)? Try this:

Dim aStyle As Style
For Each aStyle In ActiveDocument.Styles

If InStr(aStyle.NameLocal, “Heading”) Then aStyle.Font.Name = “Adobe Garamond”

Next
End Sub

Here’s the line of interest:

If InStr(aStyle.NameLocal, “Heading”) Then aStyle.Font.Name = “Adobe Garamond”

The line uses a macro command we haven’t seen before, InStr, which checks to see if a specific string of text is used somewhere. In this case, it checks to see if the text “Heading” appears in the name (NameLocal) of the style currently represented by aStyle. If it does, then the name of the font used in that style is set to Adobe Garamond.

You could even specify the exact name of the style to be changed:

If aStyle.NameLocal = “Block Quote” Then aStyle.Font.Name = “Adobe Garamond”

And that should give you an idea of how to modify a bunch of styles, all at once (between “For Each” and “Next”), to use various fonts:

If aStyle.NameLocal = “Poem” Then aStyle.Font.Name = “Arial”

If aStyle.NameLocal = “Author” Then aStyle.Font.Name = “Apple Boy”

If aStyle.NameLocal = “Subtitle” Then aStyle.Font.Name = “Constantia”

Much more can be done to automate the formatting of text using macros. I hope this brief article will get you started.

How to Add Macro to Word & to the QAT

Here’s how to put this macro (or any other) into Microsoft Word so it will be available when you need it:

  1. Copy the text of the macro, starting with the first “Sub” and ending with the last “Sub.”
  2. Click the “View” tab on Microsoft Word’s ribbon.
  3. Click the “Macros” button.
  4. Type a name for the macro in the “Macro name” box — probably the name used after the first “Sub.” For this macro, that’s “CleanCellEndSpaces.”
  5. Click the “Create” button.
  6. Delete the “Sub [macro name]” and “End Sub” lines that Word created in the macro window. The macro window should now be completely empty (unless you already have other macros in there).
  7. Paste the macro text at the current insertion point.
  8. Click “File,” then “Close and Return to Microsoft Word.”

To actually use the macro:

  1. Place your cursor at the beginning of the document.
  2. Click the “View” tab on Microsoft Word’s ribbon.
  3. Click the “Macros” button.
  4. Click the name of your macro to select it.
  5. Click the “Run” button. (If you wanted to delete the macro, you could press the “Delete” button instead.)

Here’s how to put the macro on Word’s QAT (Quick Access Toolbar):

  1. Locate the QAT (it’s probably on the top left of your screen either above or below Word’s Ribbon interface).
  2. Right-click the QAT.
  3. Click “Customize Quick Access Toolbar.”
  4. Under “Choose commands from:” click the dropdown list and select “Macros.”
  5. Find and select your macro in the list on the left.
  6. Click the “Add” button to add it to the QAT.
  7. Click the “OK” button to finish.

Jack Lyon (editor@editorium.com) owns and operates the Editorium, which provides macros and information to help editors and publishers do mundane tasks quickly and efficiently. He is the author of Microsoft Word for Publishing Professionals and of Macro Cookbook for Microsoft Word. Both books will help you learn more about macros and how to use them.

May 7, 2014

The Business of Editing: Backing Up Is Easy to Do

The title of this article put me in mind of a Neil Sedaka concert I attended more than 50 years ago. So before getting into backups, I thought we would take a trip down my memory lane. The two videos are of the same song, but performed at different tempos. The song was a big hit in both tempos, but 50 years ago, it was the faster version that made number 1 on the charts. Here is Neil Sedaka and his song, “Breaking Up is Hard to Do”:

The faster, peppier version

The slower, more “soulful” version

Now onward…

My computers are my livelihood. But as we know, computers go bad, they get stolen, viruses infect them — in other words, disaster preparedness needs to be in my vocabulary.

In prior articles (see, e.g., Business of Editing: Preparing for Disaster), I talked about how I have gone from fixed internal hard drives to removable internal hard drives as one method of protecting myself. And removable hard drives are really a boon. If you recall, I also wrote about twice getting hit with a ransomware virus that stopped me cold until it was removed at some expense (see Business of Editing: URLs, Authors, & Viruses).

Even then, my data was well protected, but I wasn’t able to return to work within seconds, which is my goal. I had to wait until the ransomware was removed because the ransomware didn’t let me access my computer so that I could access backups.

Last week I took the next step in my quest for protection. I upgraded my computer. My computer has been so stress-free and satisfactory, that the last major overhaul was about 5 years ago. Previously, I replaced my computers every 18 to 24 months.

This overhaul was essentially building a new computer. I replaced the RAM (and doubled it to 16 GB), the motherboard, the processor (went from a dual core to a quad core), a couple of hard drives (replaced older drives with two 2 TB hard drives and added a third solid state drive [SSD]), and the video card. Basically, I kept the case (I’ll never give up my Antec case), my three monitors, and my two SSDs.

In terms of performance, the new computer is like lightning compared to the previous version. My Journals macro currently has a dataset of more than 27,500 entries (and is constantly growing); it is my benchmark for speed. On the prior system took approximately 20 to 25 minutes to run through 800+ references; on the new system, it took 10 minutes to run through 883.

I’m drifting; back to backups.

One of the reasons for the upgrade was that I wanted to modify how I was doing backups. Previously, I relied largely on Carbonite for offsite backup and Backup4All for onsite. This worked well when combined with the removable drives — until the ransomware struck. That demonstrated to me a weak link in my system.

With the upgrade, I have added a 2-TB drive just for imaging backups, a second 2-TB drive for the Backup4All backups, and a third SSD that is a clone boot drive.

For the imaging, I purchased Acronis 2014 software (3-license version). I have set it to do a full image of my boot and data drives every 3 days; between those times it is set to do incremental backups. The Backup4All does daily backups of my full data drives and of select files on the boot drive. Carbonite backs up files that change from both the boot and data drives.

But the key to my new procedure is the third SSD drive. That drive, like all of the other drives, is removable and “hot swappable.” More importantly, that drive is a clone of my boot drive.

When malware strikes, it generally seeks to infect the boot drive. After all, if it only infects a data file, the cure is easy and the malware is just an annoyance, not a major problem. But if it infects the boot drive, it becomes a major problem and headache. The ransomware is such a problem because it prevents you from accessing your boot drive to get at it.

With my clone boot drive, should I be infected, I simply pop out the infected boot drive and insert the clone boot drive. I now have a running computer as if never struck by the malware. Granted, I will need to do some updating of a few of the files on the boot and data drives, but that takes a few minutes and is easy to do from Carbonite, Backup4All, or the Acronis image. I can then put the infected drive in another slot and reformat it. Once the drive is reformatted, I can use the Acronis software to clone the boot drive to the reformatted drive and I’m set should malware strike again (or even the boot drive fail).

Of course, I want the clone drive to be as current as possible, so I use Acronis to update the clone drive daily. I usually do it first thing in the morning after bootup, when I am confident that I do not have an infection on my system.

Each of the programs I use for backing up include a scheduler. When first installed, it took a few minutes to set the scheduler for each program, but once that was done, the backups take place when scheduled and in the background. How much easier can it be?

The keys to successful backups are (1) establishing a backup schedule and adhering to it, (2) using established software that is popular and well supported (and something more than barebones like what comes with Windows), and (3) using removable drives.

The removable drives are important because I can physically separate the drives from the computer. Thus, if someone steals my computer, all they are getting is the shell: The important material, the data, is elsewhere.

The removable drives are also important for malware protection, because they let you have a clone boot drive. Even if I cannot or do not want to deal with an infected drive myself, having the removable drives lets me remove the infected drive, replace it with a clone so I can go back to work, and give the infected drive to my computer tech for him to deal with. My downtime is the time it takes to swap the drives and update the few files that need updating, 30 minutes at most.

In talking with colleagues, I find that few are prepared for disaster. Perhaps now is the time to rethink our disaster preparedness and figure out what we can do should disaster strike.

Richard Adin, An American Editor

May 5, 2014

Lyonizing Word: Removing Spaces at the End of Table Cells

Removing Spaces at the End of Table Cells

by Jack Lyon

Authors do funny things. Sometimes these things are inadvertent; sometimes they’re the result of trying to “prettify” documents for publication. In either case, editors have to clean up what the authors have done.

One such problem is spaces at the ends of table cells. A table cell should end with the text it contains. If there are spaces after that text, they can cause alignment (and other) problems if they’re allowed to persist into typesetting.

It should be a simple matter to clean up the extraneous spaces: Search for a space followed by an end-of-cell marker and replace with just an end-of-cell marker. But what magic code can we use to find or replace an end-of-cell marker? As it turns out, there isn’t one. But we can still get rid of those spaces with a macro. Here it is, with comments about what’s going on (text following a single quotation mark is a “comment”, which is also in green for clarity):

The Macro

Sub CleanCellEndSpaces()

‘Define variables (that is, containers for information)
Dim aTable As Table
Dim aCell As Cell
Dim aRow As Row
Dim aColumn As Column
Dim aRange As Range ‘That is, a specific area of the document
Dim aLen As Integer ‘That is, a number
Dim LastChar As String ‘That is, a string of characters (text)

Dim Tracking As Boolean ‘True or False
Tracking = ActiveDocument.TrackRevisions ‘Get setting of revision tracking
ActiveDocument.TrackRevisions = False ‘Turn off revision tracking

On Error Resume Next ‘In case of tables with “vertically merged” cells
‘Cycle through tables, rows, and cells

For Each aTable In ActiveDocument.Tables
For Each aRow In aTable.Rows
For Each aCell In aRow.Cells

CheckAgain:

Set aRange = aCell.Range ‘Set aRange variable to the contents of the current cell
aRange.End = aRange.End – 1 ‘Don’t include the end-of-cell marker
aLen = Len(aRange.Text) ‘Get the length of the cell’s text
aString = aRange.Text ‘Assign the text to a variable
LastChar = Right(aString, 1) ‘Get the last character of the text
If LastChar = ” ” Then ‘If the last character is a space

aRange.Text = Left(aRange.Text, aLen – 1) ‘Set the text to be itself minus the trailing space
GoTo CheckAgain ‘Go back and check for another space (there may be several)

End If
Next aCell
Next aRow
Next aTable

ActiveDocument.TrackRevisions = Tracking ‘Set revision tracking back to its original state

End Sub

The Explanation

Here’s how the macro works.

We start by “dimensioning” (defining) our variables, like this:

Dim aTable As Table

“aTable” is an arbitrary name; I just made it up. But that whole line tells Word that aTable will represent a table in our document. The other “Dim” statements follow suit, with “aCell” representing a table cell, “aRow” representing a table row, and so on.

These three lines deserve special attention:

Dim Tracking As Boolean
Tracking = ActiveDocument.TrackRevisions
ActiveDocument.TrackRevisions = False

Dimensioning the “Tracking” variable as Boolean tells Word that the variable will be either true or false; those are the only two values it can hold.

Next, we set “Tracking” to the value of ActiveDocument.TrackRevisions. If revision tracking is on, “Tracking” will be set to “True.” If revision tracking is off, “Tracking” will be set to “False.” We do that to remember the current setting for revision tracking, because the next line, “ActiveDocument.TrackRevisions = False” actually turns revision tracking off (we’ll reset it later). This is necessary because (1) tracking the deletion of those extraneous spaces isn’t needed, and (2) using revision tracking may send this macro into an endless loop as it keeps “finding” the character that it just deleted (but is still there as a tracked revision).

The next line —

On Error Resume Next

— needs to be there in case a table includes “merged” cells, which will cause an error when the macro runs. If that happens, the macro will skip to the next line, which means that tables with “merged” cells will be ignored. There may be a better way to deal with such tables, but I don’t know what it is.

After that line, things get really interesting:

For Each aTable In ActiveDocument.Tables

This tells Word to work on “Each” table in ActiveDocument.Tables. “What’s that?” you ask. Well, obviously “ActiveDocument” is the active document — the document that’s open in Word with our cursor moving around in it. (Other documents may be open but not active.) In the active document, there’s a collection of objects called “Tables” — which are, of course, the tables in the document.

And now, a brief digression: As far as macros are concerned, a Microsoft Word document is “simply” a collection of various objects, such as tables, headers, footers, footnotes, endnotes, paragraphs, words, and much, much more. All of these objects have certain “properties.” For example, a paragraph may have the property of FirstLineIndent set to “True” — in other words, its first line is indented. Objects can also contain other objects. For example, a table always contains at least one row and one column. So, in our macro, we have this:

For Each aRow In aTable.Rows

That tells Word to work on each row in the current table. Similarly, this —

For Each aCell In aRow.Cells

— tells Word to work on each cell in the current row.

Next, we’re going to set the range of text we want to use (that is, aRange) to be the current cell:

Set aRange = aCell.Range

Then we’ll reduce the end of that range by one character, so we don’t include the end-of-cell marker:

aRange.End = aRange.End – 1

And, using the Len command, we’ll find out the length (number of characters) included in the range’s text:

aLen = Len(aRange.Text)

Now let’s get that text by putting it into the variable called “aString”:

aString = aRange.Text

And we’ll use the Right command to find out the last character of the text string (that is, the first character on the right of the string):

LastChar = Right(aString, 1)

That looks a little complicated, but it’s actually fairly simple. Let’s say our text string is “Hi, Mom!” The “1” tells the Right command at which character to start counting (from the right of the string). In other words, LastChar is assigned the last character of the string, which in this case is an exclamation mark (“Hi, Mom!”).

But what if the last character is a space? That’s what we really we want to know. The next line will tell us if that’s the case:

If LastChar = ” ” Then

If the last character is a space, we need to get rid of it, which we can do like this:

aRange.Text = Left(aRange.Text, aLen – 1)

That line changes the text of our range to itself minus its last character (if the previous line identified its last character as a space). But what if there’s more than one space? We want to get rid of those spaces too! And that’s where the next line comes in:

GoTo CheckAgain

That sends the macro back to the “label” we’ve created at this line:

CheckAgain:

And the operation is repeated on the cell until no more spaces remain at the end of the cell.

All of the “Next” commands that follow repeat the whole operation for every cell in every row in every table of the active document. Powerful stuff!

Finally, the macro restores revision tracking to its original setting as stored in the “Tracking” variable:

ActiveDocument.TrackRevisions = Tracking

As they taught us in kindergarten, it’s good to clean up after yourself.

This article is a brief introduction to manipulating Word “objects” with macros. Future articles may explore more of those objects, along with their “properties” and “methods.” If that’s more than you want to know, you may still find the macros themselves to be useful.

How to Add Macro to Word & to the QAT

Here’s how to put this macro (or any other) into Microsoft Word so it will be available when you need it:

  1. Copy the text of the macro, starting with the first “Sub” and ending with the last “Sub.”
  2. Click the “View” tab on Microsoft Word’s ribbon.
  3. Click the “Macros” button.
  4. Type a name for the macro in the “Macro name” box — probably the name used after the first “Sub.” For this macro, that’s “CleanCellEndSpaces.”
  5. Click the “Create” button.
  6. Delete the “Sub [macro name]” and “End Sub” lines that Word created in the macro window. The macro window should now be completely empty (unless you already have other macros in there).
  7. Paste the macro text at the current insertion point.
  8. Click “File,” then “Close and Return to Microsoft Word.”

To actually use the macro:

  1. Place your cursor at the beginning of the document.
  2. Click the “View” tab on Microsoft Word’s ribbon.
  3. Click the “Macros” button.
  4. Click the name of your macro to select it.
  5. Click the “Run” button. (If you wanted to delete the macro, you could press the “Delete” button instead.)

Here’s how to put the macro on Word’s QAT (Quick Access Toolbar):

  1. Locate the QAT (it’s probably on the top left of your screen either above or below Word’s Ribbon interface).
  2. Right-click the QAT.
  3. Click “Customize Quick Access Toolbar.”
  4. Under “Choose commands from:” click the dropdown list and select “Macros.”
  5. Find and select your macro in the list on the left.
  6. Click the “Add” button to add it to the QAT.
  7. Click the “OK” button to finish.

Jack Lyon (editor@editorium.com) owns and operates the Editorium, which provides macros and information to help editors and publishers do mundane tasks quickly and efficiently. He is the author of Microsoft Word for Publishing Professionals and of Macro Cookbook for Microsoft Word. Both books will help you learn more about macros and how to use them.

March 31, 2014

Lyonizing Word: Deleting Extraneous Carriage Returns in Footnotes and Endnotes

Deleting Extraneous Carriage Returns
in Footnotes and Endnotes

by Jack Lyon

During my editing career, I’ve often run into problems with footnotes and endnotes in Microsoft Word. Many authors have no clue about how notes are meant to work, and Microsoft certainly hasn’t made it obvious. In fact, they’ve made it easy to mess notes up beyond repair.

One mistake authors make is to insert extraneous carriage returns before or after a note. Why? Because they don’t like the positioning of the note on the page, which they’re trying to make “pretty,” not understanding the problems that will cause in editing and typesetting.

You can try to remove the extraneous returns like this:

1. Click View > Draft.
2. Click References > Show Notes.

Your cursor should now be in the Notes pane.

3. Click Home > Replace.
4. In the “Find What” box, enter two paragraph codes:

^p^p

5. In the “Replace With” box, enter one paragraph code:

^p

 6. Click the “Replace All” button.

Word will replace some of the double returns, but not all of them. And if you try to delete some of the remaining returns, you’ll get an error message:

“This is not a valid action for footnotes.”

What’s going on there is that not all carriage returns are created equal. Some of the returns are “special” note returns, and the only way to delete them is to delete the note itself back in the text.

The solution? A macro, of course. But a macro with a twist. As we’ve seen, the macro can’t just find double returns and replace them with a single return. And trying to delete extra returns results in an error. So let’s use that error!

Before running the macro, you must be in Draft view, with your cursor at the top of the Notes pane. (How to get there is explained above.)

In the macro, you’ll see a couple of “comments,” which are explanations or instructions intended for the person reading the code. Comments are preceded by a single quotation mark (‘), which tells the macro to ignore the rest of the text on that line. For example, the first comment in the macro reads:

‘To clean returns in endnotes rather than footnotes, change “.Footnotes” to “.Endnotes” in the following line:

And now, here’s the macro:

Sub CleanReturnsInNotes()
‘To clean returns in endnotes rather than footnotes, change “.Footnotes” to “.Endnotes” in the following line:
NoteCount = ActiveDocument.Footnotes.Count
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find

.Text = “^p^p”
.Replacement.Text = “”
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False

End With
Selection.Find.Execute
On Error GoTo TrapTheError
While Selection.Find.Found

Selection.MoveLeft
‘The following line may trigger an error!
Selection.Delete
Selection.Find.Execute

Wend
GoTo TheEnd
TrapTheError:

ErrorCount = ErrorCount + 1
Selection.MoveRight
Selection.Delete
If ErrorCount < NoteCount Then Resume Next

TheEnd:
End Sub

Let’s look at some of those lines.

NoteCount = ActiveDocument.Footnotes.Count

NoteCount is a variable; that is, it’s a container that can hold a numerical value—in this case, the number of footnotes in the document. We get that value with the VBA command ActiveDocument.Footnotes.Count.

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting

Just to be safe, these lines clear any formatting that might already be applied to the “Find What” and “Replace With” boxes in Word’s find and replace feature.

The following lines, from

With Selection.Find

down to

Selection.Find.Execute

simply find any instances of double paragraph returns. The replacement text is set to nothing, as we’re not trying to replace those returns with anything:

 .Replacement.Text = “”

Instead, we’re going to try to delete the second return, which (unless the notes are really messed up) is a regular return rather than a special note return:

 Selection.MoveRight
Selection.Delete

If it’s a special note return, then trying to delete it will cause an error, and the macro will execute this line—

On Error GoTo TrapTheError

—which sends the macro to this line:

TrapTheError:

Here’s what happens next:

ErrorCount = ErrorCount + 1

Using the variable ErrorCount, we count the number of errors, adding 1 each time we find one. (ErrorCount is initially empty, or zero.)

Selection.MoveRight
Selection.Delete

We move right and delete the next return.

 If ErrorCount < NoteCount Then Resume Next

If the number of errors is less than the number of notes, we’re not through yet, as one of the remaining notes may still have a bad return next to it. So, we tell the macro to Resume operation at the next command after the error occurred. That command is:

Selection.Find.Execute

In other words, Word looks for the next occurrence of a double return. And this construction—

While Selection.Find.Found

Selection.MoveLeft
‘The following line may trigger an error!
Selection.Delete
Selection.Find.Execute

Wend

—ensures that it will keep looking as long as (While) double returns are found. (“Wend” is short for “While End”—it marks the end of the While construction.)

GoTo TheEnd

When no more double returns are found, this line is executed. It exists simply to avoid executing the error trap (TrapTheError and the following lines) after the macro is finished, at which point

TheEnd:

marks the end of the whole operation.

I hope this explanation has helped you understand better how macros work, and in particular how you can actually use Word errors to force Word to do what you want it to do—something that gives me great pleasure.

Even if you don’t understand everything that’s going on in this macro, you can still use it to clean up extraneous returns in notes—something that should make your editorial life a little bit easier.

Jack Lyon (editor@editorium.com) owns and operates the Editorium, which provides macros and information to help editors and publishers do mundane tasks quickly and efficiently. He is the author of Microsoft Word for Publishing Professionals and of Macro Cookbook for Microsoft Word. Both books will help you learn more about macros and how to use them.

March 3, 2014

Lyonizing Word: The Next Character Macro

Today’s column by Jack Lyon marks the first essay in a new monthly series, “Lyonizing Word.” In this series, Jack will discuss using Microsoft Word, especially macros, to best advantage during the editing process. Please welcome Jack as a new columnist for An American Editor.

______________

Lyonizing Word: The Next Character Macro

by Jack Lyon

Macros and mastering Microsoft Word are keys to success in the business of editing. One can be a great editor and not master either, but it is more difficult, if not near-impossible, to have a successful editing business if you aren’t master of the tools you use.

My plan is to help you master Word and Word macros. My hope is that you will learn from each of my columns and will take the lessons learned and build on them yourself — for example, by building more complex and more useful macros that fulfill a need in your editing business. Here’s my first installment, which I hope you’ll find useful.

The NextCharacter Macro

I often use character codes while finding and replacing in Microsoft Word. What’s a character code? Here are some common ones:

^09 is a tab
^13 is a carriage return
^32 is a space

Especially in a wildcard search, you may have to use such codes because Word’s wildcard search engine can’t handle certain characters and will give you an error message if you try to use them.

But what if you don’t know the code for the character you need? You can probably look it up online or in a computer book, but wouldn’t it be nice to have a macro that would tell you immediately? Just put your cursor in front of the character and run the macro to get the code number. Here’s a macro that will do just that:

Sub NextCharacter()
Dim NextChar As String
NextChar = Str(AscW(Selection))
MsgBox “The code for the next character is” & NextChar
End Sub

That’s pretty simple, but there’s still a lot going on. Let’s look at each line in the macro.

Sub NextCharacter()

Here we tell Word the name of the macro, which is a subroutine (Sub) named NextCharacter. You can use pretty much any name you like, as long as it doesn’t start with a number or include any spaces. And the parentheses at the end of the name? I’ll reserve that discussion for a future article.

Dim NextChar As String

I just made up the name NextChar but not the commands around it, all of which are part of VBA (Visual Basic for Applications), Microsoft’s programming language for Word and other programs in the Office suite. If you want to learn more about “Dim,” “As,” “String,” and other VBA commands, here’s a good place to start: Getting Started with VBA in Word 2010.

In this line, we’re “dimensioning” (Dim) a variable to hold a value (NextChar) that we’ll use later in the macro. A variable is just a placeholder that can hold a value, like X in your high-school algebra class. Dimensioning just tells Word what *kind* of value we’re using — in this case, a string of characters rather than, say an integer, which can only hold numbers.

NextChar = Str(AscW(Selection))

This assigns a value to the NextChar variable. What value? The one produced by this:

Str(AscW(Selection))

“Selection” is the character to the right of your cursor (in the Western world).

“AscW” tells Word to find the ASCII or Unicode value of that character.

“Str” turns that value into a string — that is, characters rather than a value. Why? So we can see those characters in the message box produced by the next line:

MsgBox “The code for the next character is” & NextChar

This displays a message box (MsgBox) that gives us the code for the next character (as stored in NextChar), preceded by the text “The code for the next character is” just to pretty things up.

End Sub

This line simply ends the macro, or subroutine.

Now, here’s how to put this macro (or any other) into Microsoft Word so it will be available when you need it:

  1. Copy the text of the macro, starting with the first “Sub” and ending with the last “Sub.”
  2. Click the “View” tab on Microsoft Word’s ribbon.
  3. Click the “Macros” button.
  4. Type a name for the macro in the “Macro name” box — probably the name used after the first “Sub.” For this macro, that’s “NextCharacter.”
  5. Click the “Create” button.
  6. Delete the “Sub [macro name]” and “End Sub” lines that Word created in the macro window. The macro window should now be completely empty (unless you already have other macros in there).
  7. Paste the macro text at the current insertion point.
  8. Click “File,” then “Close and Return to Microsoft Word.”

To actually use the macro:

  1. Place your cursor directly in front of the character you want to identify.
  2. Click the “View” tab on Microsoft Word’s ribbon.
  3. Click the “Macros” button.
  4. Click the name of your macro to select it.
  5. Click the “Run” button. (If you wanted to delete the macro, you could press the “Delete” button instead.)

After the macro runs, a dialog box will appear with the numeric code for the character. To dismiss the dialog box, click OK.

Now that you know the code for the character after your cursor, you can use that code in Word’s Find dialog. Or you can insert it into your document. To do so, hold down the ALT key and enter the code on the numeric keypad. For example, the code for an uppercase A is 65. You could insert that character by holding down the ALT key and entering 65 on the numeric keypad. Of course, it’s a lot easier just to hold down SHIFT and hit the A key, but what if you need to enter something more esoteric? Microsoft provides a code chart here: ANSI Character Codes Chart.

That’s it! I hope you find the macro useful, and that my explanation here helps you understand a little more about how macros work.

Jack Lyon (editor@editorium.com) owns and operates the Editorium, which provides macros and information to help editors and publishers do mundane tasks quickly and efficiently. He is the author of Microsoft Word for Publishing Professionals and of Macro Cookbook for Microsoft Word. Both books will help you learn more about macros and how to use them.

November 22, 2013

Articles Worth Reading: More on Ransomware

Recently, I wrote about being attacked by ransomware (see Business of Editing: URLs, Authors, & Viruses). It appears that the problem is getting worse. I thought you would be interested in this short Ars Technica article (and the comments that follow it):

Soaring price of Bitcoin prompts CryptoLocker ransomware price break.”

The ransomware mentioned in the article is even more frightening (to me) than the ransomware I “caught,” and makes clear that it is more important than ever to regularly backup and image my hard drives.

Although the article is short, it is worth spending a few minutes to read. There are a lot of comments, but the first few are enough to emphasize the danger of ransomware and the need to be increasingly vigilant.

November 13, 2013

Business of Editing: URLs, Authors, & Viruses

Filed under: Computers and Software — americaneditor @ 4:00 am
Tags: , , ,

One of the things I most dislike about editing is the need to check author references. Aside from the mishmash manner in which the references are provided (e.g., it is not unusual to find two journal cites, one following the other, in completely different formats), I find that I am becoming increasingly angry at having to check URLs.

The Internet Age has brought many positive things to our world, but one negative is that authors increasingly cite URLs as a reference. Aside from the transience of URLs, they present a hazard to the editor who has to verify them.

Checking URLs has become expensive for me. Why? Because the links provided have become dangerous.

Twice in the last 3 months, I have inadvertently (i.e., unknown to me) downloaded ransomware (malware) to my computer as a result of clicking an author’s reference URL cite. Each of those incidents cost me several hundred dollars to remedy. In addition, my antivirus/antimalware software has protected me against another half dozen potential threats.

I’m not so angry about the threats against which I was protected by my antivirus software as I am about the ransomware ones that cost me money to cure. Fortunately, I have a local computer expert (the person who built and maintains my computers) who is willing to put me at the top of the list when I have a problem. Of course, it also means I pay for the service — and clients are unwilling to reimburse that expense.

What happened is that I clicked on a URL, found it was not good, and then moments later found that I could not access my computer’s primary screen — instead, I was faced with a demand for $300 to unlock my computer. Apparently, this is a regular scam. Sometimes the demand is labeled as coming from the FBI, sometimes it is from Homeland Security. According to my computer expert, if you pay the $300, you get a code to “unlock” the screen but then, sometime down the road, it locks up again and another demand for payment is made.

At least this bit of malware is less vicious than it could be. It only blocks access to the screen; it doesn’t attack data files.

I would be less angry about this if I thought the authors even cared a little bit, but considering that 75% of the URLs cited in the reference list in the latest project were either invalid (the URLs returned “Error 404: File Not Found” errors) or took me to clearly irrelevant sites, I have little faith in the idea that the author cares that at least one of the listed cites caused major problems for me — and would do the same for the reader who decided to check the cite.

We all know that the Internet can be a dangerous place. For the young, it is a source of never-ending bullying; for the elderly, it is a way to lose life savings; and for editors who have to check the validity of a cited URL, it is a way to infect one’s computer and suffer financial loss.

I am also mad at myself for getting caught by this malware twice. I am very careful about how I use the Internet and I make sure that I use up-to-date protection software. I even use the “pro” versions so that I get hourly updates. I also avoid likely troublesome sites. And for years I never suffered an invasion of malware.

Getting caught twice in 3 months is making me wonder what else I can do. It is hard to avoid the risk exposure when I have to check URLs as part of my job. And there is no way to know (at least not that I am aware of) in advance that a particular URL is going to make me wish I was retiring.

One colleague suggested that I simply not check URLs. Unfortunately, I cannot see an ethical way to do that. Instead, I am thinking of adding a clause to my “contract” that basically says, “client warrants that all URLs cited in the manuscript are virus- and malware-free. In the event that verifying a cited URL causes a virus or malware attack on my computer and/or network, client agrees to pay the cost of expert removal plus for my lost work time.”

I suspect that few clients would be willing to accept such a clause, especially if the client is a publisher or service provider rather than the author. But I need to do something, and the additional clause seems the best option at the moment. It would at least make my client aware of the potential for the problem.

For those of you who are interested in seeing what this particular virus is about, here is a link to Yoo Security. Should you get the virus, getting rid of it is a problem because you can’t easily access your desktop and rebooting doesn’t get around the problem. I suggest that you go now to your antivirus software’s website and search for ransomware under Support. There should be an article that tells you the steps you need to take to rid your computer of this malware. Print it and save it. Even if you can’t do it yourself, it may save you some money when you have someone else do the fix.

Have you experienced virus or malware attacks from client files? How did you deal with it?

October 28, 2013

EditTools 5.1 with Code Inserter Released

A new version of EditTools has been released. It is available at wordsnSync and is a free upgrade to current registered users of EditTools.

In addition to some minor bug fixes, version 5.1 includes a powerful, new macro, Code Inserter — an easy way to insert codes into a manuscript — and Assign Hotkeys — a new function that provides an easy way to assign hotkey combinations to EditTools macros.

Code Inserter

The idea behind Code Inserter is to make inserting codes, such as <ca>…</ca>, quick and easy. Code Inserter is a new top-level menu item. The process begins with the Insert Code Manager, which is shown here:

Code Inserter 3

As you can see from the image, there is a lot going on in the Manager. The Manager has the usual Open and New options. You can create a generic coding system for a client or one tailored to a specific project. You can also copy codes from one file to another using the Move/Copy Codes button.

If it is a new file, the Manager will be empty. You enter a name for the code in the Name: field (Chapter Author in the example) and the code that is to appear in the manuscript in the Code: field (<ca> in the example). You then indicate where the code is to be inserted: At the start of the line (At Start), at the location of the cursor (At Cursor), or at the end of the line (At End). You also indicate whether, after inserting the code, your cursor should move to the next line automatically. Finally, you indicate whether an end code is needed.

If you look in the main data field (where all of the codes in the dataset are listed), you will see that Chapter Author is highlighted. By looking across, you can see the name you gave the code, the code that will be entered, and which options you chose for that code (the Xs).

Note the Setup Hotkey button. Hotkeys are a new feature for several of the EditTools macros. This allows you to assign a key combination to run the macro. As shown in the image below, you can assign any keyboard combination to be the hotkey for this macro. (The hotkey runs the Code Inserter macro; it does not open the Manager.)

Code Inserter 4

When you run the Code Inserter macro, it brings up the box shown below, listing all of the codes you have created alphabetically by the name you assigned to the code.

Code Inserter 5

Just click on a code’s name or the checkbox next to the name, and the code will be automatically inserted according to the instructions you gave.

Code Inserter 6

If you also need an end code and checked that option for this particular code in the Manager, this dialog box will appear:

Code Inserter 7

Clicking OK will cause the end code to be inserted where you indicated and your cursor will return to where the beginning code was placed.

Code Inserter 8

As currently setup, to run Code Inserter you either need to click on Code Inserter in the main menu, then Run Code Inserter in the drop down menu, and finally on the code to be inserted. Alternatively, if you assigned a hotkey to the macro, you can press that key combination and then click on the code to be inserted.

However, there is a third option: You can assign to the main menu bar a Run CI button. The Code Inserter menu has an option called Activate “Run CI” Button. If you click this option, a button called Run CI appears in the main menu bar as shown below. Instead of using a hotkey to activate the macro, you can use this button. (The Deactivate “Run CI” Button deactivates this button and removes it from the menu bar.)

Code Inserter 9

Hotkeys

New in version 5.1 is an easy method for assigning certain macros to hotkeys. Not all of the macros are assignable; only those macros that are likely to be used more than once while editing a document. For example, it is expected that the Never Spell Word macro will be run just once on a document, whereas the Enhanced Search, Count, & Replace macro might be run multiple times.

In the case of Toggle, you run its Manager, and for Insert Query, you run the macro to access the Setup HotKey button. The Toggle Manager is shown below:

hot key 1

For those macros that can have hotkeys assigned to them but that do not have Managers, you access the Setup by going to Preferences > Hotkeys > Setup Hotkey for Macro, as shown in the image below. This opens a dialog from which you can choose which macro(s) you want to assign to a hotkey.

hot key 4

The other macros for which hotkeys currently can be set are Enhanced Search, Count, & Replace and Smart Highlighter. Select the macro to which you want to assign a hotkey, and then click the Setup Hotkey button. When done click Close.

hot key 3

These enhancements to EditTools have been under beta testing for a while and the reports are that Code Inserter has made coding quicker, easier, and typing-error free.

Information about these and the other macros included in EditTools is available at wordsnSync. If you haven’t tried EditTools, you should. To download the latest version of EditTools, go to the Downloads page and click on “Download EditTools v5.1″.

If you are interested in the ultimate deal, take a look at “A Special Deal: Editor’s Toolkit Ultimate!” This package includes the latest versions of EditTools, Editor’s Toolkit Plus, and PerfectIt at a significant discount.

September 16, 2013

At Long Last — EditTools 5.0

It has been a long time since the last update to EditTools was released. Macros can be troublesome things, and it has taken longer than I had hoped to make some of the macros perform as I wanted.

EditTools 5.0 is a free upgrade for current registered users of EditTools. It is available at wordsnSync.

EditTools IS Usable By All Editors

Before I describe some of the enhancements in version 5, I want to discuss a couple of common misconceptions about EditTools. First, EditTools is usable by ALL editors — whether the editing subject area is STM, humanities, law, business, fiction, science fiction, or any other area. Alas, too many editors take a look at EditTools and the examples of what various macros do, see that the default labels and the examples are for medical books, and go no farther. The labels and examples are because I do medical editing and I created these macros for use in my work.

However, most of the tabs in the dataset managers are easily renamed. There is a button on the tabs titled Change Tab Name. Just click it and you can change, for example, Never Spell Words to Always Change These Words or to Matilda’s Vocabulary Checker or to whatever has more meaning for you. And the datasets that these tabs use can be named anything you want and contain the information you choose.

Although not all of the macros are usable by every editor in every editing job, most editors who use EditTools have a few macros that are favorites and used regularly; but as is true of any macro collection, there will be macros that are not used at all by a particular editor. Several of the macros that I used with great frequency 5 years ago, I rarely use today (e.g., MultiFile Find and Replace); others I use many times an hour, every day, and on every editing job (e.g., Toggle and Search, Count, & Replace). Some of the macros are intended to be used only once on a document (e.g., Never Spell Word and Journals).

My point is that if you have not tried EditTools because you think it is for STM editing only or because you  see some macros that you think you would never use, you should rethink your view of EditTools and give it a try.

I push EditTools, the Editorium’s Editor’s Toolkit Plus, and Intelligent Editing’s PerfectIt because I know, from my own experience and from the experiences users have related to me, that these three programs can help you increase your productivity, efficiency, speed, and profitability. In the case of EditTools, the need to increase those aspects of my editing is what led to the original creation, and the continuing enhancement of, EditTools.

New in EditTools 5.0

New in version 5 of EditTools are these macros: Cleanup; the complementary macros Convert Highlights to Styles & Convert Styles to Highlights; Change Style Language; and Quote Conversion. In addition, numerous fixes and enhancements have been made to other macros. What follows is a brief introduction to the new macros.

Cleanup

Although I run the Editorium macros that clean up my files, there is always something that Editorium’s FileCleaner (included in Editor’s Toolkit Plus) doesn’t do because no one would have imagined an author doing this. That’s where Cleanup comes into play.

Cleanup lets me design my own cleanup macro. It has a manager that makes it easy for me to enter things I would like changed universally without tracking on. (Cleanup does not offer the Track Changes On option.) For example, if a client wants all em-dashes changed to spaced en-dashes, I use Cleanup to do it.

Cleanup has both a general (things I want done on all files) Manager that saves to a general file, and a Specialty Manager that lets me create a separate, special cleanup file for a particular project or client. Cleanup should be run on a file before any other EditTools macro is run.

For more information, see the explanatory page at wordsnSync.

Convert Highlights & Styles

The Convert Highlights to Styles and Convert Styles to Highlights are paired macros; that is, you run Convert Highlights to Styles before you begin editing and — very importantly — before any other EditTools macro except Cleanup. Convert Styles to Highlights is the very last macro you run and — very importantly — it must be run after Remove All Highlighting.

This macro pair is useful in many situations, but here are the two primary uses I make of the macros.

The first situation is when I receive files from clients where some material has been highlighted and the client wants the highlighting to remain. Before these macros, this was problematic because EditTools relies on highlighting to communicate with the editor. Consequently, the client would receive either a file loaded with extraneous (to the client) highlighting or without any highlighting at all, unless I manually rehighlighted what the client wanted left highlighted, which would be a waste of my time and cost me money.

The second situation, which is the more usual one, is when I receive a file with no highlighting that the client wants kept but that has callouts for figures and tables (or anything else) that have to be brought to the compositor’s attention. In these cases, I like to use highlighting but haven’t been able to unless I searched for and manually highlighted each callout/item after I ran Remove All Highlighting. That wasn’t so bad when there were only a couple of tables or figures, but I have had files with dozens of each called out.

In the first instance, running Convert Highlights to Styles converts all of the client’s highlighting to a style and removes the highlight. Then, when I am done editing and have removed all of the highlighting I have added, I can run Convert Styles to Highlights and the client’s highlighting is back in place. And for callouts, I can apply the style to them so they are highlighted as well.

In the second instance, I search for the first callout and I apply highlight to it. I then run the macro to convert it to a style. This adds a style to the list of styles. Now when I come to a callout, I simply apply the style. Then, when I am done editing and have removed all of the highlighting I have added, I run Convert Styles to Highlights and all of the callouts are in highlight.

For more information, see the explanatory page at wordsnSync.

Change Style Language

I find it frustrating when I receive a file and the document language is not set to English. So, I apply English to the “whole” document only to discover that in many of the multitude of styles the document has, the language has been set to something other than English and/or Spell Check has been turned off in the style, and my attempt to set the whole document to English and turn on Spell Check has failed.

Change Language Style lets me choose a language and choose to turn Spell Check on or off and have that information made a part of each style in the document. Running the macro means it goes through all of the styles in the document and changes all of the language and spell check settings to what I have chosen. Unfortunately, it doesn’t work on all styles. Microsoft has some built-in styles that cannot be changed this way (particularly “attribute styles”), but the change is made to the great majority of styles. It may not be perfect, but it makes life easier and solves a problem editors often encounter in a minimum amount of time.

Quote Conversion

The final new macro is Quote Conversion, which has two submacros: American Quotes to British and British Quotes to American. This macro is simple but effective. If you receive a document that uses British quotes that need to be Americanized, run British Quotes to American. To go from American to British quotes, run American Quotes to British.

EditTools 5.0 adds valuable macros to an already existing array of valuable macros. Check it out and if you are a registered user, be sure to download and install your free upgrade.

July 29, 2013

Making the Decision to Move to Lightspeed

The one thing that is true about technology is that obsolescence is built-in. Whatever you buy today will, after a manufacturer-predefined time, begin to turn to dust.

Before we go further into my tale, let’s sidestep for this bit of music:

As I have mentioned in other posts, I have my computers custom built locally. That allows me to choose higher-quality components from manufacturers that I prefer. One part from here, one from there. More importantly, my local computer shop warrants those components for 3 years.

For years, I replaced our computers every 18 to 24 months. The technology was changing rapidly and by the time 2 years had passed, it was like moving from the paleolithic era of computing to the future. And the more complex my macros became and the more I wanted them to do, the greater the computing power I needed and wanted. The one thing I didn’t want was to have time to twiddle my thumbs while waiting for my macros to do their tasks.

About 6 years ago that changed with the building of our current computers. I had finally hit the top of the hill. Sure changes continued to occur and components continued to improve, but none of them would have had much of an impact on my needs. The machine I had custom built would outlive my editing career – or so I hoped.

As with all such wishes, there was something I forgot: components are designed to fail. Manufacturers don’t want things to live forever, so obsolescence is built-in.

This past week, my boot drive began to fail. I could tell because it took longer and longer to boot up my computer each morning; because where once the computer easily handled a dozen open applications simultaneously, now it struggled to hand three or four; because I would be working and suddenly everything would freeze for a few seconds.

I also began to notice that my data drive also was generating errors. Reads and writes to the data drive (a separate physical drive from my boot drive) took a little bit longer; instructions weren’t being carried out quite as fast (or so it seemed) as in previous times.

Although these two hard drives were high-quality drives when purchased, time had passed them by. All traditional-type hard drives have moving parts, parts that eventually wear out. The one thing I didn’t want to happen was for the drive to start writing data to bad sectors, causing corruption, so I took the hints I was being given and called my local computer shop.

It took 3 hours of downtime, but in that time, I went from what now seems like crawling to near the speed of light. It previously took a little more than 90 seconds to boot up; now it takes less than 20 seconds. The cure was not only new drives but going to solid-state drives (SSDs).

Unfortunately, SSDs are expensive, at least double the price of traditional drives. But with that increased price comes compactness (four SSDs fit within the same space as one traditional drive), no moving parts to wear out (although these drives do eventually lose the ability to write to the disks, they, supposedly, never lose the ability to read from them), no heat generation, and no noise (no moving parts to make noise).

An advantage of custom building my computers is the ease with which these types of repairs can be made. As I have noted previously, all of my hard drives are hot swappable, which means that I can pull them out of their slot without turning off and opening the computer, and I can put a different hard drive in the slot and access it. It makes for great backup and for easy storage when I travel. It also means that my computer shop could do the repair in my office — I didn’t need to be without the computer for more than a few hours. (Most of the time I was “down” was spent cloning my old drives to the new SSDs. The physical replacement of the drives and getting Windows to recognize the new drives took only a few minutes.)

Now that I have new primary hard drives, I am thinking about updating my remaining traditional hard drives (six of them: one for storage of completed projects; one to hold my imaging backups; four in my NAS [network-attached storage] box for my daily backups) to SSDs. I am unlikely to do that upgrade soon because of the cost and the lack of real need. None of those drives get the use that my two primary drives receive.

The upgrades I will be doing in the coming few months are upgrades to my motherboard, processor, RAM, and video cards. With the new SSDs, my Journals macro that took nearly 26 minutes to run through 15,000 dataset entries on a list of 500+ references now takes closer to 11 minutes (see Business of Editing: The Logistics of Large Projects). It will be even faster once I upgrade the motherboard, processor, and RAM to ones that can take full advantage of the SSDs.

With my computer working great with just the SSD upgrade, why would I consider spending even more money to upgrade these other components? Because I will get a high return on my investment — I will make back the cost of the upgrade in just a couple of projects. Remember, I charge by the page so that the faster and more efficiently I can process data, the higher my effective hourly rate will be (see Thinking About Money: What Freelancers Need to Understand).

In other words, I am investing in my business. My pre-SSD computer configuration performed well for about 6 years. I received an excellent rate of return on that investment. Now it is time to invest for the next 6 years (or longer). When I make decisions about whether to buy new equipment/components, the biggest factors in my decision-making process are the answers to these questions: “Will it help to increase my effective hourly rate?” and “If it will, how quickly will it do so?”

If the answer to the first question is no, then I proceed no further. The only time I will buy is when I must because of, for example, a component failure. I haven’t bought a tablet for work because a tablet can neither improve my speed/efficiency nor positively affect my effective hourly rate. If the answer to the first question is yes, but the answer to the second question is a time frame that I think is too long, such as 20 or more projects or 1 year or longer, then I also do not buy. The return on investment is not sufficient to justify the investment. I need to wait for further technological improvements.

In the case of the hard drives, the decision had to be made whether to buy traditional drives or the SSDs. I decided to buy the SSDs because the answer to the first question was yes and to the second it was no more than 2 projects to recoup the price differential; in other words, it made fiscal sense to spend more now to reap long-term benefits.

What analysis do you do when deciding whether to buy new equipment or to upgrade your current equipment or even what type of equipment to buy?

Next Page »

The Rubric Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 1,211 other followers

%d bloggers like this: