* 小花鹿 老师:下面是我前两年写的《选项对齐》宏,请试运行之,代码仅供参考。
- Sub OptionAlign()
- '选项对齐
- Dim t As Table, i As Paragraph, lenTable!, oTab!, Tab1!, Tab2!, Tab3!
- With ActiveDocument
- .Tables.Add .Range(0, 0), 1, 1
- lenTable = Round(.Tables(1).Cell(1, 1).Width / 28.35, 2)
- .Tables(1).Delete
- 'cm=char/2.7
- oTab = (Int((lenTable - 2 * 0.19) * 2.7 + 0.5) - 2) / 4
- Tab1 = Round((2 + 1 * oTab) / 2.7, 2)
- Tab2 = Round((2 + 2 * oTab) / 2.7, 2)
- Tab3 = Round((2 + 3 * oTab) / 2.7, 2)
- .Content.Find.Execute "^l", , , 0, , , , , , "^p", 2
- For Each t In .Tables
- With t.Range.Rows
- .WrapAroundText = False
- .Alignment = wdAlignRowCenter
- End With
- Next
- With .Content.Find
- .Execute "(^13)([ ^s^t]{1,})", , , 1, , , , , , "\1", 2
- .Execute "([ ^s^t]{1,})(^13)", , , 1, , , , , , "\2", 2
- .Execute "([A-D])[.、]", , , 1, , , , , , "\1.", 2
- .Execute "([ ^s^t^13]{1,})([B-D].)", , , 1, , , , , , "^t\2", 2
- .Execute "(^13)([0-9]{1,})[.、]", , , 1, , , , , , "\1\2.", 2
- End With
- For Each i In .Paragraphs
- With i.Range
- If Not .Information(12) Then
- If .Text Like "A.*" Then
- .Font.Color = wdColorRed
- With .ParagraphFormat.TabStops
- .ClearAll
- .Add Position:=CentimetersToPoints(Tab1)
- .Add Position:=CentimetersToPoints(Tab2)
- .Add Position:=CentimetersToPoints(Tab3)
- End With
- If .ComputeStatistics(1) = 2 Then
- .Find.Execute "^t(C.)", , , 1, , , , , , "^p\1", 2
- With .ParagraphFormat.TabStops
- .ClearAll
- .Add Position:=CentimetersToPoints(Tab2)
- End With
- ElseIf .ComputeStatistics(1) >= 3 Then
- .Find.Execute "^t([B-D].)", , , 1, , , , , , "^p\1", 2
- End If
- With .ParagraphFormat
- .CharacterUnitFirstLineIndent = 0
- .FirstLineIndent = CentimetersToPoints(0)
- .CharacterUnitFirstLineIndent = 2
- End With
- End If
- End If
- End With
- Next
- End With
- End Sub
复制代码 |