WordBasic Macro: Moving Through Each Cell in a Table

Last reviewed: February 5, 1998
Article ID: Q122049
The information in this article applies to:
  • Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c

SUMMARY

When you write Word for Windows macros, you may need to move through each table cell applying formatting or inserting text. The following sample macro uses a While loop to move through each cell in the table, formatting the contents of each cell with bold formatting.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Sub MAIN
If SelInfo(12) = - 1 Then
 TableSelectTable
 StartOfRow
 EditGoTo "\cell"
 FormatFont .Bold = 1
 While NextCell() <> 0
  EditGoTo "\cell"
  FormatFont .Bold = 1
 Wend
End If
End Sub

The following macro instructions are used to move the insertion point to the beginning of the table:

   TableSelectTable
   StartOfRow

The EditGoTo instruction uses the reserved "\cell" bookmark to select the contents of the cell so that formatting can be applied to the text. A While loop is used to move through each cell in the table. The NextCell() function returns a 0 (zero) when the insertion point is within the final cell of the table. The following macro instruction loops through the cells in the table while the NextCell() function returns a value other than 0 (zero):

   While NextCell() <> 0

REFERENCES

"Microsoft Word Developer's Kit," version 6.0, pages 52-53


KBCategory: kbusage kbmacro
KBSubcategory:
Additional reference words: 6.0 6.0a 6.0c loop table While word6
Wend NextCell cell winword
Version : 6.0 6.0a 6.0c
Platform : WINDOWS


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 5, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.