技术
您现在的位置:首页 >> 技术

WORD公文正文排版VBA宏代码

Sub 公文正文排版()

Dim Fie As Field

PRT = 2

Selection.WholeStory

'页面设置

With ActiveDocument.PageSetup

.TopMargin = CentimetersToPoints(3.7)

.BottomMargin = CentimetersToPoints(3.5)

.LeftMargin = CentimetersToPoints(2.8)

.RightMargin = CentimetersToPoints(2.6)

.PaperSize = wdPaperA4

.HeaderDistance = CentimetersToPoints(1.5)

.FooterDistance = CentimetersToPoints(2.8)

.OddAndEvenPagesHeaderFooter = False

End With

'段落设置

With ActiveDocument.Paragraphs

.Alignment = wdAlignParagraphJustify

.LeftIndent = CentimetersToPoints(0)

.RightIndent = CentimetersToPoints(0)

.CharacterUnitFirstLineIndent = 2

.LineSpacingRule = wdLineSpaceExactly

.LineSpacing = 28

End With

With ActiveDocument.Content.Font

.Name = "仿宋_GB2312"

.Size = 16

.Color = wdColorBlack

End With

'标题设置

ActiveDocument.Paragraphs(1).Range.Select '选中文档的第一段

With Selection

.ClearFormatting

With .Font

.Size = 22

.Name = "方正小标宋简体"

End With

With .Paragraphs

.CharacterUnitFirstLineIndent = 0

.Alignment = wdAlignParagraphCenter

.LineSpacingRule = wdLineSpaceExactly

.LineSpacing = 35

End With

Selection.Range.HighlightColorIndex = wdYellow

Selection.MoveDown unit:=wdParagraph

Selection.TypeParagraph

.HomeKey unit:=wdStory

End With

'页脚设置

'奇偶页相同

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter

With Selection

.WholeStory

.Delete

.TypeText "--"

.MoveLeft wdCharacter, 1

.Fields.Add Selection.Range, -1, "Page", True

.MoveRight wdCharacter, 1

.WholeStory

With .Font

.Name = "宋体"

.Size = 14

End With

.ParagraphFormat.Alignment = wdAlignParagraphRight

End With

'奇偶页不同

If PRT = 2 And (Selection.Information(wdNumberOfPagesInDocument) > 1) Then

ActiveDocument.PageSetup.OddAndEvenPagesHeaderFooter = True

ActiveWindow.ActivePane.View.SeekView = wdSeekEvenPagesFooter

With Selection

.WholeStory

.Delete

.TypeText "--"

.MoveLeft wdCharacter, 1

.Fields.Add Selection.Range, -1, "Page", True

.MoveRight wdCharacter, 1

.WholeStory

With .Font

.Name = "宋体"

.Size = 14

End With

.ParagraphFormat.Alignment = wdAlignParagraphRight

Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft

End With

End If

ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

Selection.HomeKey unit:=wdStory

End Sub