Article ID: 203479
Article Last Modified on 1/23/2007
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