WD: ToolsCalculate w/ Combination Cell Range and Table Bookmark

Last reviewed: February 2, 1998
Article ID: Q113836
The information in this article applies to:
  • Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Word for the Macintosh, versions 6.0, 6.0.1

SYMPTOM

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 : kbmacroexample macword ntword winword word6 word7 word95 wordnt kberrmsg kbmacro
Version : WINDOWS:2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a; MACINTOSH:6.0,6.0.1,6.0.6.0.1a
Platform : MACINTOSH Win95 WINDOWS winnt
Issue type : kbdocerr
Solution Type : kbworkaround


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 2, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.