|
楼主 |
发表于 2019-3-31 23:27
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
leedun 朋友,你好!——你的示例文本弄丢了形如“(一)XX”和“1.XX”这两种标题层次,我也不知道你是怎么想的(多级标题和编号,我从未应用过,所以,我的公文标题只有标准的四个层次,我的《集成版》你有时间可以按 F8 键逐一测试一下,就明白了我的排版思路)。但是,按照你的愿望,请试试下面的代码(只设置了样式,段落间距(即段前/段后)、与网格对齐未取消,具体格式设置请自行处理):
- Sub test()
- '第X章后加全角空格
- With ActiveDocument.Content.Find
- .Execute "(^13第[一二三四五六七八九十百零〇○]@章)", , , 1, , , , , , "\1 ", 2
- .Execute "(^13第[一二三四五六七八九十百零〇○]@章)([ ^s^t]{1,})", , , 1, , , , , , "\1 ", 2
- End With
- '核心
- Dim s$, i As Paragraph, n&
- s = "一二三四五六七八九十1234567890百零〇○"
- For Each i In ActiveDocument.Paragraphs
- With i.Range
- n = 1
- If .Text Like "[第(]*" Then n = 2
- Do While InStr(s, .Characters(n)) > 0
- n = n + 1
- If .Characters(n).Text = "、" Then .Style = wdStyleHeading2: Exit Do
- If .Characters(n).Text = "章" And Not .Text Like "(#*" Then .Style = wdStyleHeading1: Exit Do
- ' If .Characters(n).Text = "." Then .Style = wdStyleHeading4: Exit Do
- If .Characters(n).Text = ")" And .Text Like "(#*" Then .Style = wdStyleHeading3: Exit Do
- Loop
- End With
- Next
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|