Geekgirl’s Before Hours Blog

Entries in Microsoft Word (5)

Tip: Delete the open document in Microsoft Word

Have you ever wanted to delete the document currently open in Word? I find I often want to do this when I’m trying to clean out a whole bunch of old documents: I open each one, check the contents and, if I no longer need it, delete it on the spot.

Word won’t normally let you do this: you must first close the document, then delete it. That’s a sensible safeguard, but sometimes it gets in the way of what you want to do.

Using a macro, you can get around this restriction and delete the active document. Note that because you cannot undelete any document you eliminate using this macro, it takes some preliminary precautions:

  • First, the macro checks that there is, in fact, an open document to delete.
  • If there is an open document, it checks that the user really wants to delete it. If not, the macro ends without doing anything else.
  • If the user gives the go ahead to delete the document, the macro checks to see whether the open document has already been saved. If it has, the document is closed and then deleted. If it has not yet been saved, it is simply closed without saving any changes.

To create the macro:

  1. Press Alt+F8 to open the Macros dialog.
  2. Type DeleteActiveDocument in the Name box and click Create.
  3. Copy and paste the following code between the Sub DeleteActiveDocument()and the End Sub statements (Note: if you want, you can download a full text copy of the code, complete with comments describing what it’s doing at each stage):
Sub DeleteActiveDocument()


Dim strFileToDelete As String
Dim docOpen As Document
Dim intDocCount As Integer

intDocCount = 0

For Each docOpen In Documents
   intDocCount = intDocCount + 1
Next docOpen

If intDocCount > 0 Then

   If MsgBox(“Are you sure you want to delete the open document permanently? ” & _
   “You won’t be able to undo this action.”, vbYesNo) = vbYes Then

      If Len(ActiveDocument.Path) <> 0 Then

         strFileToDelete = ActiveDocument.FullName
         ActiveDocument.Close SaveChanges:=False
         Kill strFileToDelete

      Else

         ActiveDocument.Close SaveChanges:=False

      End If

   End If

Else

   MsgBox “There is no open document to delete.”, vbOKOnly

End If

End Sub

  1. Close the Visual Basic editor.

Add it to Word’s toolbar

To make the macro easily accessible, add it to the Quick Access Toolbar in Word 2007:

  1. Click the arrow at the right end of the Quick Access Toolbar and select More Commands.
  2. In the Choose Commands From box, select Macros from the drop-down list.
  3. Click the newly created macro (it’s full name is Normal.NewMacros.DeleteActiveDocument) and then click the Add button.
  4. Click the Modify button, select an appropriate icon for the macro (there’s a handy one with a cross in a red circle that fits well), type Delete This Doc in the Display Name box and click OK.

To add the macro to a Word 2003 toolbar:

  1. Right-click any toolbar and click Customize.
  2. On the Commands tab in the Categories list click Macros.
  3. Locate Normal.NewMacros.DeleteActiveDocument in the Commands list and click-and-drag it onto a toolbar.
  4. Right-click the new button you’ve created, in the Name box type Del (or something else short and descriptive), then click Text Only. If you’d prefer to use a graphic icon instead of a text-label, although none of the default icons is particularly apt you can create your own by selecting Default (instead of Text Only). Then click Edit Button Image, then Clear and then do a quick paint job (a red X works well).
  5. Click Close in the Customize dialog box.

If you have any problems running the macro, take a look at the code in the Visual Basic editor and make sure you don’t have any broken lines. That’s the usual cause of problems.

Tip: Automatically open last edited document in Word

If you frequently find yourself wanting to edit the same document you were using in your last Word session, you can create a shortcut which does just this, using a command-line switch.

Here’s how:

  1. Right-click an empty spot on your desktop and choose New -> Shortcut from the pop-up menu.
  2. Click the Browse button and locate the winword.exe program. If you installed Word in the default folder and you’re using Word 2003, you’ll find it in C:\Program Files\Microsoft Office\Office11; if you’re using Word 2007, it’s in C:\Program Files\Microsoft Office\Office12. Click winword.exe when you locate it and then click Open. Windows will automatically fill the location box with the full pathname surrounded by quotation marks.
  3. Click within the location box and, after the closing quotation marks, add a space followed by /mfile1, then click Next.
  4. Give your shortcut a name, such as Last Word, and click Finish.
  5. If you like, drag your newly created shortcut onto the Quick Launch bar to the right of the Start button to make it easier to use.

Put them somewhere handy

I like to place both shortcuts side by side in the Quick Launch bar: the normal Word shortcut and my Last Word shortcut. That way, I can choose whether to launch Word with a blank document or with the last-edited document pre-loaded. I distinguish between the two by altering the icon for the Last Word shortcut:
  1. Right-click the Last Word shortcut and select Properties from the pop-up menu.
  2. On the Shortcut tab, click Change Icon.
  3. Click one of the alternative icons and click OK.

Almost the same thing with a macro

Note that it’s also possible to open the last-edited document using a macro, but this method has the drawback of making Word always launch with that document loaded. If that’s what you want to do, here’s how to create the macro:

  1. Press Alt+F8 to display the Macros dialog.
  2. Type AutoExec in the Macro Name box and click Create. The Visual Basic Editor will load.
  3. In the code window on the right, you’ll see that Word has automatically created a code stub for the AutoExec macro. Between the Sub AutoExec() and End Sub statements, on a line by itself, type:

RecentFiles(1).Open

  1. Close the Visual Basic editor.

The commands you stick in a macro named AutoExec run automatically whenever you launch Microsoft Word, so creating this AutoExec macro will open the most recently edited document every time you launch Word.

Posted on Sunday, July 20, 2008 at 06:44AM by Registered CommenterRose Vines in , , , , | CommentsPost a Comment

Tip: Using Microsoft Word's spike to rearrange text

Microsoft has long produced software with a belt-and-braces approach, offering a choice of ways to perform a particular task.

For example, in Word, you’ll find a smorgasbord of methods for cutting, copying and pasting text. There’s the usual cut, copy and paste via keystroke, menu or toolbar. There’s also the Office Clipboard, which is like copy-and-paste on steroids. Then there’s the often-overlooked spike, which sits halfway between the other two methods in terms of power.

The spike lets you quickly reorganize snippets of text and graphics. You grab the snippets from different locations in your document, place them one by one on the spike, then use the Insert From Spike command to paste them as a block into your document.

The spike didn’t qualify for inclusion in Word’s menus or toolbars, but you can easily access it using the keyboard: Ctrl+F3 cuts the selected text and places it on the spike; Ctrl+Shift+F3 copies the entire contents of the spike into the document at the current location.

So if you’re working on a masterpiece such as this:

Oil, that is. Black gold. Texas tea.
A poor mountaineer, barely kept his family fed,
When up through the ground came a bubblin’ crude.
Then one day he was shootin’ at some food
Come listen to a story ’bout a man named Jed

and decide a little rearranging would improve its readability, select the fifth line and press Ctrl+F3; then line 2 and press Ctrl+F3; line 4, Ctrl+F3; line 3, Ctrl+F3; line 1, Ctrl+F3; and finally press Ctrl+Shift+F3 to paste the newly arranged result:

Come listen to a story ’bout a man named Jed
A poor mountaineer, barely kept his family fed,
Then one day he was shootin’ at some food
When up through the ground came a bubblin’ crude.
Oil, that is. Black gold. Texas tea.

Of course, the spike really comes into its own when you’re writing something a little more weighty and need to rearrange entire paragraphs or sections to create the best flow.

Spike’s idiosyncracies

There are several things worth noting about the spike.

  • First, the spike uses a separate area of memory from the Windows and Office clipboards. So you can press Ctrl+C to copy an item to the clipboard, then subsequently press Ctrl+F3 to cut an item to the spike, and the contents of the clipboard will remain untouched. When you press Ctrl+V the contents of the clipboard will be pasted into the document; when you press Ctrl+Shift+F3 the contents of the spike will be inserted.
  • While the Windows Clipboard can hold a single item at a time and the Office Clipboard can hold 24, the spike has a voracious appetite and is happy to accommodate thousands of items.
  • When you insert the contents of the spike into the document using the Insert From Spike command (Ctrl+Shift+F3), the spike is emptied. This contrasts with the behavior of the clipboard, where the contents remain available for pasting and re-pasting until you replace the contents by cutting or copying another item. If you’d prefer to keep the contents of the spike intact while pasting it into your document, it helps to know that when you cut the first item to the spike, in the background Word creates an AutoText entry called ‘spike’; the entry is deleted after you press Ctrl+Shift+F3. So if, instead of pressing Ctrl+Shift+F3 to insert the spike, you instead type spike and press F3, Word performs the usual AutoText actions instead: it copies the contents of the ‘spike’ AutoText entry without deleting it.
  • The spike is shared by any documents you have open. You can spike an item from the first document, switch to the second and spike three items there, switch back to the first document and insert all four items.
  • Things get a little tricky when you try to add the contents of a table to the spike. If you select the table and then press Ctrl+F3, the only thing that gets spiked is the contents of the table’s first cell. This is because Word stops ‘spiking’ when it hits the first paragraph mark, and, because it treats the end-of-cell marker as a paragraph mark, it copies that first cell’s contents then stops. To get around this, make sure you select the entire table plus the paragraph mark following the table. It may help to click the Show/Hide button on the toolbar so you can quickly spot the paragraph mark.

Avoiding blank lines

You may find it useful to switch off Smart Paragraph Selection in order to avoid creating blank lines between each of the items on the spike.

With Smart Paragraph Selection enabled, it’s impossible to select a paragraph without grabbing that final paragraph mark as well. If you spike the series of lines from our previous example with Smart Paragraph Selection enabled, you’ll end up with this:

Come listen to a story ’bout a man named Jed

A poor mountaineer, barely kept his family fed,

Then one day he was shootin’ at some food

When up through the ground came a bubblin’ crude.

Oil, that is. Black gold. Texas tea.

If you switch Smart Paragraph Selection off, you can select a paragraph minus the paragraph mark by dragging carefully to the text end; you can still grab the paragraph mark if you want to by dragging past the “end” of your paragraph to include the mark. You can also grab a paragraph complete with its paragraph mark by placing the cursor in the left-hand margin and dragging down.

To turn Smart Paragraph Selection off, in Word 2007 click the Office Button -> Word Options -> Advanced and deselect Use Smart Paragraph Selection. In Word 2003, click Tools -> Word Options -> Edit tab and deselect Use Smart Paragraph Selection.

Posted on Wednesday, June 18, 2008 at 04:43PM by Registered CommenterRose Vines in , , , , | Comments2 Comments

Using Microsoft Word's hidden calculator

You’ve probably heard the stats: 80% of Microsoft Word users make use of only 20% of its features. My guess is that only about 0.1% of Word users use the handy calculator built right into the program.

I’m not talking about the SUM() and AVERAGE() fields or any of the other of Word’s useful but not particularly elegant mathematical tools. I’m talking about a simple, straightforward calculator which lets you perform any basic arithmetical operation anywhere within Word.

You haven’t heard about it? Don’t worry, even Microsoft has no information about this feature, unless you dig way back into its archives where you’ll find that the calculator – which formerly held a prominent position on the Tools Menu – was driven underground in Word 6.0 to make way for the far more cumbersome, albeit more powerful, formula field.

It’s true Windows comes with a more advanced calculator built in, but if you spend your days working in Word, nothing beats having a calculator right there in front of your nose at all times.

Unearthing the calculator

Because Microsoft has buried the calculator so thoroughly, you’ll need to resurrect it before putting it to use. That means sticking it on a toolbar. In Word 2007, you’ll have to put it on the Quick Access toolbar:

  1. Right-click the Quick Access toolbar and select Customize Quick Access Toolbar from the pop-up menu.
  2. Make sure For All Documents is selected in the Customize Quick Access Toolbar drop-down box.
  3. In the Choose Commands From drop-down box, select Commands Not In The Ribbon. (Side note: Perusing this list is highly educational for old-time Word users pining for lost commands.)
  4. Locate Calculate in the list and double-click it to add it to the list of Quick Access commands, then click OK.

In Word XP/2003, do this:

  1. Right-click any of your toolbars and choose Customize from the pop-up menu.
  2. Click the Commands tab in the Customize dialog.
  3. In the Categories list click Tools and in the Commands list scroll to Tools Calculate.
  4. Click and drag the Tools Calculate command onto any of your toolbars.
  5. To display a more compact icon, right-click the Tools Calculate button on the toolbar, select Change Button Image and pick the calculator icon. Right-click the Tools Calculate button once more and select Default Style. Then click Close.

What the calculator does

With the Calculator now ensconced on a toolbar, you’re ready to give it a whirl.

The calculator handles addition, subtraction, multiplication, division, percentages, exponentiation and roots. It takes six operators:

  • Addition: +
  • Subtraction: - or place the number to be subtracted in parentheses, ( )
  • Multiplication: *
  • Division: /
  • Percentages: %
  • Exponentiation and roots: ^

If you omit the operator, the calculator assumes you want to add the numbers. So you can write:

235 79 9412 17.95 432.82

then select the numbers and click the Calculator button. The result (10176.77) is displayed, briefly, in Word’s status bar. The result is also stored on the clipboard, so you can press Ctrl+V to paste it into your Word document or copy it into another program.

Calculate anywhere 

Unlike formula fields, the calculator works anywhere, including in paragraphs containing intervening text. Thus if you use the calculator on the following sentence:

At the dinner there were 13 doctors, 25 cosmologists, 53 seismologists and 219 assorted hangers on.

the total number at the dinner will be calculated. Note, though, that if your text includes characters such as =, - or * you’ll confuse the calculator and end up with an error.

You can also use the Calculator in tables to tot up numbers in columns, in rows or in the whole table. As in ordinary text, use parentheses around a number or a minus sign before it to denote a negative number in the table.

Take care: although it’s possible to select numbers in non-adjacent cells in a table by holding down the Ctrl key while you select each cell, the calculator will not give you a correct total if you try to add these numbers. Your selection must contain contiguous cells, rows or columns.

Try it out

Try out a few simple examples to get an idea of what you can do with the calculator:

  • Simple addition and subtraction: 12+9-17.5
  • Simple multiplication: 123*52
  • Simple division: 9.3/7
  • Calculating a percentage: 3422*17%
  • Exponentiation: 7^4
  • Calculating a cube root: 1728^(1/3)

Note that you don’t need to use an equals sign; in fact, Word will give you an “!Unexpected end of formula” error if you do.

Ordering

The calculator uses operator precedence and parentheses to determine the order of calculations in more complex expressions. For example:

12+9*2^3

gives you the answer 84, while:

12+(9*2)^3

produces the result 5844.

If you don’t include parentheses in an expression, Word performs operations in this order:

  1. percentage
  2. power and root
  3. multiplication and division
  4. addition and subtraction.

Mind your parentheses!

When using parentheses, you need to keep your wits about you. Take these four expressions:

  • 17(8)
  • 17(2^3)
  • 17*(8)
  • 17*(2^3)

The results are, respectively, 9, 25, (136) and 136. In the first example, the calculator subtracts 8 from 17; in the second, it adds 8 (2 raised to the 3rd power) to 17; in the third, it multiplies 17 and -8; and in the last it multiplies 17 by 8. The second expression, in particular, is worth noting: the calculator performs the expression within the parentheses and then discards the parentheses, resulting in a final expression of:

17 8

The two figures are then added to produce 25.

Office for Mere Mortals

I’ve recently started writing for Office for Mere Mortals. I wrote for this email newsletter some time back but took a break for a while. It’s a collection of tips and tutorials on Microsoft Office aimed at regular users, not tech-heads.

You can subscribe for free using the link above, but I’ll also be publishing some of the tips here on Before Hours. I’ll kick it off with a couple of Word tips.

Selecting a column of text

Most text selection in Word involves selecting horizontally – selecting a line or a paragraph of text. Sometimes, though, you need to select a vertical slab of text. To do that, hold down the Alt key while you click and drag your mouse over the text.

1465693-1461144-thumbnail.jpg
Hold down the Alt key to select columns of text
This comes in handy when someone sends you an email or other document with the lines indented. When you copy the email into Word, you end up with empty space at the beginning of each line. To instantly eliminate the spaces and shift the whole block of text over, hold down the Alt key, click immediately to the left of the first character in the top line, then drag down and to the left to highlight the spaces. Press Delete to erase them. You can use the same technique to eliminate unwanted characters when you copy an email into Word in which each line has been preceded with a quote character, such as >.

You can also use this technique to select a vertical column within a slab of text, although this works best when you’re dealing with monospaced fonts where each character is the same width.

Rand() gets a facelift

One of Word’s quirky, tucked-away features is the rand() function. It lets you quickly insert a block of text in a document. To use the function in pre-2007 versions of Word, at the beginning of a line type =rand() and press Enter. Word inserts three paragraphs, each containing five sentences like this:

The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.

To vary the number of sentences and paragraphs produced, add parameters to the function. For example, =rand(5,7) produces five paragraphs each containing seven sentences, while =rand(15,2) produces 15 paragraphs containing two sentences each.

Why would you want to do this? Well, it’s useful if you want to try out formatting or quickly whip up a document to demonstrate some of Word’s features. The sentence contains all the letters of the alphabet, so it’s particularly handy when you want to compare fonts.

In Word 2007, rand() gets a makeover. It no longer displays a sentence containing all the letters in the alphabet; instead, it produces three paragraphs of text explaining how to perform basic formatting actions.

It’s a shame Microsoft didn’t take this a bit further and include a sizeable number of Word 2007 tips rather than the meagre three paragraphs offered; that would have made rand() a really useful training aid. As it is, although you can no longer use rand() to display all the characters in a particular font, the more varied text – nine different sentences instead of the dizzingly repeated “quick brown fox” – makes rand() much more useful as a formatting aid. Use the text to test how page flow works in a document template or for positioning pictures or tables in a page and then flowing the text around them.

For the curious, the maximum value for rand is rand(200,99) or rand(99,200). If you try that in Word 2007 you’ll end up with almost half a million words inserted into your document and, if your PC isn’t speedy, a long wait. Use with caution!

Posted on Tuesday, April 1, 2008 at 10:33PM by Registered CommenterRose Vines in , , , , | Comments1 Comment