|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub a724_选项对齐()
- 'Word2019须将代码拷贝到新建文档,再全选剪切到 VBE 中执行!否则可能乱码出错。
- Dim i As Paragraph, n!
- With ActiveDocument
- .Content.Font.Size = 10.5 '五号(全文字号,此值可自行修改)
- .Fields.Unlink '删除域
- .ConvertNumbersToText '列表编号转文本
- With .Content.Find
- .Execute "^l", , , 0, , , , , , "^p", 2 '手动换行符全部替换为段落标记
- .Execute "([0-90-9A-D])、", , , 1, , , , , , "\1.", 2 '顿号=>齐线墨点
- .Execute "^13([B-D])(.)", , , 1, , , , , , "^t\1\2", 2 '四个选项以制表符分隔形成一个段落
- .Execute "(答案)(:)", , , 1, , , , , , "\1:", 2
- End With
- '删除空行
- For Each i In .Paragraphs
- If Asc(i.Range) = 13 Then i.Range.Delete
- Next
- '循环遍历所有段落
- For Each i In .Paragraphs
- With i.Range
- If .Text Like "#.*" Then
- n = 1.5
- ElseIf .Text Like "##.*" Then
- n = 2
- End If
- If .Text Like "A.*" Then
- .Select
- With Selection
- '文本转表格
- .ConvertToTable Separator:=wdSeparateByTabs, NumColumns:=4, _
- NumRows:=1, AutoFitBehavior:=wdAutoFitFixed
- '表格转文本
- .Rows.ConvertToText Separator:=wdSeparateByTabs, NestedTables:=True
- '左缩进1.5/2字符
- With .ParagraphFormat
- .CharacterUnitLeftIndent = n
- .LeftIndent = CentimetersToPoints(0)
- End With
- '判断段落行数
- If .Range.ComputeStatistics(1) = 1 Then
- Else
- .Range.Find.Execute "^t(C.)", , , 1, , , , , , "^13\1", 2
- '判断段落行数
- If .Range.ComputeStatistics(1) > 2 Then
- .Range.Find.Execute "^t([B-D].)", , , 1, , , , , , "^13\1", 2
- End If
- End If
- End With
- ElseIf .Text Like "答案*" Then
- '左缩进1.5/2字符
- With .ParagraphFormat
- .CharacterUnitLeftIndent = n
- .LeftIndent = CentimetersToPoints(0)
- End With
- End If
- End With
- Next
- End With
- Selection.HomeKey 6 '光标移至文首
- MsgBox "处理完毕!", 0 + 48
- End Sub
复制代码 |
|