Microsoft KB Archive/203479

= WD97: Macro Example for Formatting Table Cells That Contain Text =

Article ID: 203479

Article Last Modified on 1/23/2007

-

APPLIES TO


 * Microsoft Word 97 Standard Edition

-



This article was previously published under Q203479





SUMMARY
The following macro is an example of how to select each cell in a table, test the cell for text, and then format only the cells that contain text.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

173707 OFF97: How to Run Sample Code from Knowledge Base Articles

Sub EditMyTable

' Test if in a table. If Selection.Information(wdWithInTable) Then

' Set myRange as the document work area. Set myRange = Selection.Range

' Set oTable as the selected table. Set oTable = myRange.Tables(1)

' Loop through the cells of the table. For Each acell In oTable.Range.Cells

' Sets myCell equal to the text minus the end-of-cell marker. Set myCell = ActiveDocument.Range(Start:=acell.Range.Start, _     End:=acell.Range.End - 1)

' Formats cell if # of characters greater than zero. If Len(Trim(myCell)) > 0 Then acell.Shading.Texture = wdTexture10Percent End If

' Goes to next cell of table Next acell

Else

' Returns a message if insertion point not in a table. MsgBox "You Are Not In A Table"

GoTo Bottom: End If

MsgBox "This Macro Is Finished"

Bottom:

End Sub For additional information about programming assistance, click the article numbers below to view the articles in the Microsoft Knowledge Base:

163425 WD97: Macro Programming Resources

163435 VBA: Programming Resources for Visual Basic for Applications

Additional query words: kbcode kbmacro vba

Keywords: kbdtacode kbhowto kbmacroexample kbprogramming KB203479

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.