|
* 功能:如果存在发文字号则设置格式;否则插入发文字号并设置格式。
* 修改:代码中有 4 处“可修改”的地方,可改为自己单位发文所用数据。
- Sub 发文()
- Const s As String = "委发" '可修改
- Dim r As Range, i&, j As Paragraph
- With ActiveDocument
- With .Content.Find
- .Execute "[^13^l]", , , 1, , , , , , "^p", 2
- .ClearFormatting
- .Text = "^13[!^13]@[:。:]"
- .Forward = True
- .MatchWildcards = True
- .Execute
- If .Found = True Then
- With .Parent
- .Select
- With Selection
- .HomeKey 6, 1
- .MoveEnd
- .ClearFormatting
- CommandBars.FindControl(ID:=122).Execute
- With .Font
- .NameFarEast = "宋体"
- .NameAscii = "Times New Roman"
- .Bold = True
- .Kerning = 0
- .DisableCharacterSpaceGrid = True
- End With
- With .ParagraphFormat
- .LineSpacing = LinesToPoints(1.15)
- .AutoAdjustRightIndent = False
- .DisableLineHeightGrid = True
- End With
- Set r = .Range
- With r
- For Each j In .Paragraphs
- If Len(j.Range) = 1 Then j.Range.Delete
- Next
- With .Paragraphs(1).Range
- If Not .Text Like "*〔[0-9][0-9][0-9][0-9]〕*号*" Then .InsertBefore Text:=s & "〔" & Format(Date, "yyyy") & "〕" & "X号" & vbCr
- End With
- With .Paragraphs(1).Range
- .InsertParagraphAfter
- .InsertParagraphBefore
- End With
- .Characters.Last.InsertParagraphBefore
- i = .Paragraphs.Count
- End With
- End With
- End With
- End If
- End With
- .Paragraphs(1).Range.Font.Size = 108 '可修改
- With .Paragraphs(2).Range.Font
- .Name = "仿宋"
- .Size = 16
- End With
- .Paragraphs(3).Range.Font.Size = 36 '可修改
- .Range(Start:=.Paragraphs(4).Range.Start, End:=.Paragraphs(i - 1).Range.End).Font.Size = 22
- .Paragraphs(i).Range.Font.Size = 26 '可修改
- End With
- End Sub
复制代码 |
|