|
测试下列代码前,请自行备份好原文档。
- Sub RowsShadingGray()
- Dim wRng As Range, sRng As Range, cRng As Range, wTab As Table, iRow As Integer
- On Error Resume Next
- Application.ScreenUpdating = False
- Selection.GoTo wdGoToPage, , , "20" 'InputBox("请输入起始页码:", , 20)
- Set wRng = ActiveDocument.Range(Selection.Range.Start, ActiveDocument.Range.End - 1)
- For Each wTab In wRng.Tables
- ActiveDocument.Range(wTab.Cell(3, 1).Range.Start, wTab.Cell(wTab.Rows.Count, wTab.Columns.Count).Range.End).Select
- Selection.Shading.BackgroundPatternColor = wdColorAutomatic
- Selection.Sort , "列1", wdSortFieldNumeric, wdSortOrderAscending
- For iRow = 1 To wTab.Rows.Count
- wTab.Cell(iRow, 1).Select
- Selection.SelectRow
- Set cRng = Selection.Cells(Selection.Cells.Count).Range
- If ActiveDocument.Range(cRng.Start, cRng.End - 1) = "0" Then
- Selection.Shading.BackgroundPatternColor = wdColorGray25
- End If
- Next
- Next
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|