本帖最后由 413191246se 于 2022-10-1 20:56 编辑
* 在学习 tangqingfu 兄的《Word查找和替换的实例和方法》的帖子时,浏览到了另一个《选项对齐》的帖子。前一段我也写了此宏,方法是文本转表格、表格再转文本;又观 守柔版主(顾问)并未用表格,而我用表格实在是下策,速度必然慢。后来,又反复录制设置、清除制表位的宏,略有心得,遂从昨晚直到现在,终于完成此宏的试用版,希望能给需要的朋友们带来方便(英文过程名可以自行改为中文过程名)。
* 为精简代码,仅针对 ABCD 四个选项,用制表位分隔,速度较快,结果还算差强人意,敬请各位朋友们试用,谢谢!
* 祝论坛各位朋友——国庆节快乐!
* 示例文档:
OptionAlignDemo.rar
(11.5 KB, 下载次数: 50)
- 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
复制代码 |