Search This Blog

Monday, 13 May 2013

Macro tricks in Word, part 1

Warning: I am out-of-date, and still use Word 2003.  YMMV!

Note also that I am a seriously old code-hacker and my mind is convoluted from all the time I have spent being smart-lazy.  That means I look for back doors and handles that I can use to turn things on their heads.  In 1981, with no word processor available to use on my Commodore PET, which had a massive 32k or RAM, I wrote my own—in BASIC!!

So yes, my mind is a bit weird, but if you work through these pieces, you will gather some useful tricks, and save yourself a lot of time.

It was furst drafted back in 2005, but never actually saw the light of day, because it was too hard to clarify, and I was busy. I revived it to help people to make sense of the talk I gave in 2012. Use it as a source of practical solutions which can be pillaged.

Using Macros in Word, and other tricks

Some years back, I mentioned on a list that there are many things that can be done with macros. I was asked to explain in more detail and I ducked, being a bit busy, but the time has come to actually talk to the issue, because there seems to be a bit of a lack of good background on the tricks of the trade. I am going to start several steps back, because the effective use of macros works best if you have set the document up in a particular way, which brings us to styles. You don't have to do it my way, but if you are going to follow my discussion later on, it relates to how I use a particular setup.

I plan to discuss ways of improving productivity by spending a short period to get things right, and as well as macros, I will talk about autocorrect, which can be another useful tool. You will find that this relates closely to what I do (and why). My aim is to introduce you to some wrinkles that you can sift through for the ones that fit you. The adept will adapt and adopt, I hope.

Styles

I only use Times New Roman: I can change that if I need to for a special purpose, but I like to keep stuff plain and simple. Almost everything I do uses 4 levels of heading (18 point, 16 point, 14 point and 12 point bold), a Normal (no indents, 12 point, left-justified) and Normal indent, which is like Normal, but with the first line indented by 1 cm. Styles can be set up to specify what the next paragraph will be: when you hit 'Enter' from one of my Headings, the next paragraph is automatically normal, and when I hit enter again, the paragraph after is Normal indent, as are the paragraphs that follow that. Eventually, I add another heading, and the cascade starts again. 

For special cases, I may add a style called qquote, which is 10 point Times New Roman, justified, indented 1cm each side, with a box around it. The paragraph that follows is Normal again - this being the usual print convention. 


You set up styles by going to Format - style and choosing a style to modify. If you are unfamiliar with this, it is worth doing carefully. To make them permanent, you need to open the file normal.dot (it is a good idea to make a back-up copy first!) which is a template - then modify the styles and save the result.

Getting creative with styles

This is a bit of a side-issue, but I have spent a number of years in my life working rather closely with multiple choice questions, and this led me to consider the time wasted in getting multiple choice questions to come out just right. That was when I had the bright idea of creating styles called Stem (the question part) and OptionA, OptionB, OptionC and OptionD.

As you will see later, these can be used in a macro that saves lots of time, but let's just look at the styles for now.

The style that is specified to follow Stem is OptionA, and the style after that is OptionB and so on. The style after OptionD is Stem once more. OptionD is different from the others, since it leaves a larger spacing after it (12 points instead of 3 points), and unlike the others, is not flagged with "keep with next", a neat little option that says in effect "keep all of a set of paragraphs on the same page" - so the questions never split over two pages.

The main part of this trick is that, having established the style for the first line, all of the rest is automatic. Now let's look at some of the handy things you need to know.

Did you know?

Some of the tips here do not relate directly to my topic, but were thrown in because I happened to think of them. If you are creative, you may see a way to use them. This is my blog, and I will amble and ramble as I please. Walk along with me!

Carriage return, tabs and other specials

You can search for a carriage return, and end of paragraph marker, by telling the Word program to look for ^p, while a tab is ^t and a soft return is ^l. (By the way, 'carriage return' is one of those leftovers from the era of the electric typewriter and the line printer, a character that required the system to perform a line feed, down one line, and back to the start of the line. A soft return is Shift-Enter, and it does not start a new paragraph. See the section on sorting for an application of this.

To see what else you can search for, click on Edit - More - Special to see a drop-down menu of things you can search for. Note that when I give you a sequence like that, we begin with the top menu bar, and after that, you need to look for a tab or a button that leads you to the next stage. If you are going to make Word work for you, you need to have explored most of these.

While you are in the area, click on Edit - More - Format to see how you can select only (say) for a word when it is in italics, or in a heading. Also, look over on the left to see that you can specify matching case, whole words only, and wildcards. I have never used "Sounds like" or "Find all word forms", so you are on your own there.

One key choice that you have in the extended search and replace dialogue box is to search up, search down or search all. This is of less use in a macro, but it can be very handy indeed.

Sorting

The Table - Sort function is excellent when you have a whole range of, say, dictionary definitions, because it sorts paragraphs (usually alphabetically). There is a catch, though, if you have the title on a separate line. The solution is to use soft returns, achieved with Shift-Enter, so that the whole lump of text remains a simple paragraph. Later, when the sorting is done, and you have saved the text, you can use Edit - Replace to get rid of the soft returns (^l), replacing them with carriage returns (^p).

I usually put a # on a separate line as an end-of-entry marker when I do this. It can be deleted later, but if I want to, I can create a macro that finds the # character, moves to the next paragraph (the title of the entry) and formats it, say, to Heading 4. You have to set that up first, and that is why every system needs to be thought about before you begin.

Autocorrect

Because I write a lot of historical material, I often need the £ symbol, and it is a nuisance recalling the code that generates it: I will get to those later. Because people in the US refer to the # symbol as 'pound' sometimes, I have an Autocorrect setting that converts the string #$ to £.

This text was written in Word. Given that, you may wonder why #$ was not converted to £ here: the answer is that it was, but pressing backspace once undoes the autocorrection. You do need to think through the Autocorrects that you use, just in case something else, where you wanted that string to stand, gets converted.

For example, I created an Autocorrect to change dC to °C, but there is no case sensitivity here. That meant I got into trouble with DC current and Washington DC, so I made degC the trigger, though mostly, I just use a macro that inserts a ° symbol: I will come to that later.

As far as I am concerned, I would only ever type NEJM when I meant the New England Journal of Medicine (I write about science, OK?), so I am happy to have the autocorrect change NEJM to New England Journal of Medicine.

To make that happen, I type the phrase I want to see appear, italicise it, highlight it, and go to Tools - Autocorrect, when a dialogue box comes up, with the completed phrase on the right. Then I add the letters NEJM to the left-hand side and click on the button for formatted text, and it is all ready to go.

This is useful for things like company names as well as schools and the like. Just think of the long phrases that you do all the time, like your name and your address, and set them up as autocorrects.

Another application of autocorrect is to handle El Niño and São Tomé: at one stage, when I was writing about sugar and slavery, some years back, I set up Autocorrect to deal with the special characters in São Tomé, and I discuss El Niño often enough to have the tilde added to the second n as a matter of course.

Autotype

If you happen to write about hominin fossils a lot, you can use either Autocorrect or Autotext. I have added Sahelanthropus tchadensis to my Autotext, and I need only type the first four characters. When it comes to Australopithecus species, though, I have a number to deal with, all with the same genus name, so I need to use Autocorrect codes like A.afa and A.afr for Australopithecus afarensis and Australopithecus africanus respectively.

Codes for special characters

There are two systems of coding for special characters using the ALT key and the numbers on the numeric pad. One set is ALT-xxx, the second is ALT-0xxx. These are not to be confused with each other: ALT-129 is ü while ALT-0129 is  which is pretty useless.

Note that you need to hold down the ALT key, type three or four numbers on the numeric pad (really annoying when you have a laptop!!) and then let go the ALT key.

You can also do special characters by using Insert - Symbol and selecting the appropriate character. If you look closely when you mouse over the character you want, you will often see that there is a keyboard shortcut. Where I create ñ by typing ALT-164, I can insert it from the symbol menu which says that I can also do Control~ then letting go and typing n (note that ~ is a shifted character, so you need to hold down the shift key as well - fiddle with this one, because it also gives you ã and õ, if you ever need them. The menu also tells me to get £ by typing ALT-0163.

Suppose I want a degree symbol. This is °, which I can get with Control-Shift-2, followed by a space, but I have always found that too hard to recall, so I have a macro, coded by Control-Shift-D, which does it for me.

Word count and other toolbar bits


As you can see, my toolbar contains a lot of extras, but the most valuable is Word count, which tells me both the number of characters in a selection and the number of words in either the selection or the whole document. To add things like this, go to Tools - Customize - Command and explore, understanding that you can drag interesting commands up onto the tool-bar.

Word count is found in the Tools sub-menu. Explore!


Planning a book with a spreadsheet;
Practical use of macros and spreadsheets;
and
Macro tricks in Word, part 2.

No comments:

Post a Comment