Hack 27 Crunch Numbers Quickly in Word![]() ![]() and dirty math, dust off one of Word's oldest commands: Calculate.If you used Word when the first President Bush was in office, you might remember a handy feature from the Tools menu: the Calculate command. With the standard four functions, plus exponents and percentages, Calculate could handle a lot of the math needed for simple sales reports or budget proposals.Though Microsoft removed the command from the Tools menu in Word 6.0, you can still find it if you know where to look.
4.2.1 Resurrecting CalculateFirst, select Tools the Categories column, choose All Commands. Scroll down until you find ToolsCalculate, as shown in Figure 4-1. Figure 4-1. Locating the Calculate command buried deep in Word![]() Speech option (or anywhere else on the menu). Right-click the new menu item and rename it "Calculate," as shown in Figure 4-2. Figure 4-2. Returning Calculate to the Tools menu![]() grayed-out. Calculate is available only when you've selected some text. 4.2.2 Using CalculateBy default, the Calculate command will add any set of selected numbers separated by whitespace. Word temporarily displays the result in the status bar, as shown in Figure 4-3, and also places it on the clipboard. Figure 4-3. The sum of the selected numbers is temporarily displayed in the status bar![]() except for currency symbols, periods, and commas, which it recognizes when these are part of a number.For operations other than addition, you must include the mathematical operator. Table 4-1 lists the operations in reverse order of precedence. To force a calculation out of precedence order, enclose the expression in parentheses. Addition and subtraction are of equal precedence and are evaluated left to right. Multiplication and division also are of equal precedence and are evaluated left to right.
on any selected text. For example, you can use this command to quickly add all the numbers in a paragraph of text, as shown in Figure 4-4. Figure 4-4. Calculate works with selected text and displays the results in the status bar![]() 4.2.3 Hacking the HackThe calculation results are displayed in the status bar for only a few seconds. After that, if you want to see the results, you must either paste them from the clipboard or redo the calculation, paying closer attention to the status bar. If you prefer to display the calculation results more directly, you can intercept the command [Hack #61] and have Word display the results in a message box.Place the following macro in the template of your choice [Hack #50] . It will run in place of the Calculate command when you select Tools Sub ToolsCalculate( )However, when you intercept the command, Word neither displays the calculation results in the status bar nor copies them to the clipboard. To also put the results in the status bar, use the following code instead: Sub ToolsCalculate( )It takes a bit more work to get the results copied to the clipboard. There's no direct way to access the clipboard from VBA, so you need to use Windows API calls. You can find sample code for accessing text on the clipboard at http://support.microsoft.com/default.aspx?scid=kb;en-us;138909.With the code from that site included in the same module, use the site's example Clipboard_SetData subroutine to put the results on the clipboard: Sub ToolsCalculate( ) |