|
本帖最后由 413191246se 于 2015-7-20 22:12 编辑
* 适用于正文四号/首行缩进2字符版面,否则排版不整齐。
* 算法更新,代码减半,人员无限制!——现在《主任/副主任/成员》或《组长/副组长/成员》三组人员无限制,XXXX工作领导小组办公室主任即使达到100人也可以,副主任达到1000人也可以,成员达到1万人也可以。
* 注意事项:《主任/副主任/成员》或《组长/副组长/成员》这三个关键词,后面必须有冒号跟随(无论半角冒号还是全角冒号),否则程序无法处理。
* 适用于下列格式:(XX 或 XXX 代表人名,如:鲁迅/周树人)
主席:XXX XXX
XXX XX XXX
副组长:XXX XX XXX XX
XXX XX XXX XX
成员:XXX XX XXX XX XXX
XXX XX XXX XX XXX XXX
***《主任名单》宏(完美终结版)代码:
- Sub 主任名单()
- If Selection.Type = wdSelectionIP Then MsgBox "请选定<主任/副主任/成员>区域!", vbOKOnly + vbCritical, "主任名单": End
- CommandBars.FindControl(ID:=122).Execute
- CommandBars.FindControl(ID:=123).Execute
- Dim myRange As Range, i As Paragraph, j As Long, k As Long
- Set myRange = Selection.Range
- For Each i In myRange.Paragraphs
- If Not (i.Range Like "*[::]*") Then i.Range.InsertBefore Text:=" "
- Next
- With myRange
- .Find.Execute findtext:=":", replacewith:=":", Replace:=wdReplaceAll
- .Find.Execute findtext:=": ", replacewith:=":", Replace:=wdReplaceAll
- .Find.Execute findtext:="^t", replacewith:=" ", Replace:=wdReplaceAll
- .Find.Execute findtext:=" ", replacewith:=" ", Replace:=wdReplaceAll
- .Find.Execute findtext:="^s", replacewith:=" ", Replace:=wdReplaceAll
- .Find.Execute findtext:="^p ", replacewith:=" ", Replace:=wdReplaceAll
- End With
- Do
- myRange.Find.Execute findtext:=" ", replacewith:=" ", Replace:=wdReplaceAll
- Loop Until myRange.Find.Found = False
- myRange.Find.Execute findtext:=":", replacewith:=":^p", Replace:=wdReplaceAll
- myRange.Paragraphs(6).Range.Select: k = 3
- ConSetName:
- Selection.Find.Execute findtext:=" ", replacewith:="^p", Replace:=wdReplaceAll, Wrap:=wdFindStop
- For Each i In Selection.Paragraphs
- If Len(i.Range) = 2 Then i.Range.Characters.Last.Delete: i.Range.Characters(1).InsertAfter Text:=Space(2)
- If Len(i.Range) = 3 Then i.Range.Characters(1).InsertAfter Text:=" "
- Next
- If k = 2 Or k = 1 Then j = Selection.Paragraphs.Count
- Selection.ConvertToTable Separator:=wdSeparateByParagraphs, NumColumns:=5, AutoFitBehavior:=wdAutoFitFixed
- Selection.Rows.ConvertToText Separator:=wdSeparateByTabs, NestedTables:=True
- CommandBars.FindControl(ID:=122).Execute
- CommandBars.FindControl(ID:=123).Execute
- Selection.Find.Execute findtext:="^t", replacewith:=" ", Replace:=wdReplaceAll
- If k = 3 Then
- Selection.ParagraphFormat.CharacterUnitFirstLineIndent = 6.05
- ElseIf k = 2 Or k = 1 Then
- If j > 5 Then Selection.ParagraphFormat.CharacterUnitFirstLineIndent = 6.05
- End If
- Selection.Previous(unit:=wdParagraph, Count:=1).Select
- Selection.Find.Execute findtext:=" ", replacewith:="", Replace:=wdReplaceAll
- If k = 3 Or k = 1 Then Selection.Characters(1).InsertAfter Text:=" "
- Selection.Font.Name = "黑体"
- Selection.Font.Bold = True
- Selection.Characters.Last.Delete
- Selection.ParagraphFormat.CharacterUnitFirstLineIndent = 2
- If k = 1 Then Selection.HomeKey unit:=wdLine: End
- If k = 2 Then Selection.Previous(unit:=wdParagraph, Count:=1).Select: k = 1: GoTo ConSetName
- Selection.Previous(unit:=wdParagraph, Count:=1).Select: k = 2: GoTo ConSetName
- End Sub
复制代码
|
|