Microsoft KB Archive/113836

{|
 * width="100%"|

WD: ToolsCalculate w/ Combination Cell Range and Table Bookmark

 * }

Q113836

-

The information in this article applies to:


 * Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
 * Microsoft Word for Windows, versions 7.0, 7.0a
 * Microsoft Word for the Macintosh, versions 6.0, 6.0.1

-

SYMPTOMS
The ToolsCalculate WordBasic command gives a WordBasic error 24 "bad parameter" if the function form is used with both a cell reference and a table bookmark. The example on page 747 of the "Microsoft Word Developer's Kit" is not correct.

CAUSE
The ToolsCalculate function in Microsoft WordBasic takes the form

    ToolsCalculate([Expression$]) where Expression$ takes the form of the =(Formula) field. Expression$ can have arguments that are numbers, bookmarks, or table cells. Combinations can also be used as arguments. However, the following example (as shown on page 747), which specifies the use of specific cell references within two bookmarked tables, is not a valid expression and gives a WordBasic error 24 "bad parameter":

    total = ToolsCalculate("sum(sales a5, other b5)") This construction behaves correctly for formula fields. The following field yields the correct result:

    {= sum(sales a5, other b5)}

RESOLUTION
You can simulate the functionality of the WordBasic statement above by bookmarking cell a5 of the "Sales" table and cell b5 of the "Other" table and then adding the two bookmarks (see example 3 below).

Examples
The following are all valid uses of the WordBasic ToolsCalculate command. (Note: In the following examples, "Sales" is a bookmarked table, "Units" is a bookmarked cell whose value is 10, and "Cost" is a bookmarked number elsewhere in the document whose value is 2.5.)

 1. Total = ToolsCalculate               Total is the sum of all the selected table cells or                                           numbers. 2. Total = ToolsCalculate("a1 + a2")      Total is the sum of A1 and A2                                            for the table holding the insertion point. 3. Total = ToolsCalculate("Units * Cost") Total is 25. The insertion point position and selection are irrelevant. 4. Total = ToolsCalculate("Sales")        Total is the sum of all cells bookmarked in the table. The insertion point position and selection are irrelevant. 5. Total = ToolsCalculate("Units * 5")    Total is 50. The insertion point position and selection are irrelevant. 6. Total = ToolsCalculate("A1 * 10")      Total is 10 times the value in                                            cell A1 of the table holding the insertion point. 7. Total = ToolsCalculate("A1 * Units")   Total is 10 times the number in                                            cell A1 of the table holding the insertion point. Additional query words: err message Word Basic macro

Keywords : kberrmsg kbmacro wordnt kbmacroexample winword ntword macword word6 word7 word95

Issue type :

Technology :