|
我有一试卷模板,双栏页码,是根据一位电脑专家的技巧而设的页码,现在通过反复试验,终于把它录制成宏,成功!但未精简代码,楼主先对付着用吧,有时间再精简一下,下面是录制的宏(WORD 2003 VBA):
Sub 插入页码_双栏_第X页_共Y页()
'
' j Macro
' 宏在 2012-2-26 由 微软用户 录制
'
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(0)
.RightIndent = CentimetersToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphLeft
.WidowControl = False
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = CentimetersToPoints(0)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LineUnitBefore = 0
.LineUnitAfter = 0
.AutoAdjustRightIndent = False
.DisableLineHeightGrid = True
.FarEastLineBreakControl = True
.WordWrap = True
.HangingPunctuation = True
.HalfWidthPunctuationOnTopOfLine = False
.AddSpaceBetweenFarEastAndAlpha = True
.AddSpaceBetweenFarEastAndDigit = True
.BaseLineAlignment = wdBaselineAlignAuto
End With
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
If .Style <> "网格型" Then
.Style = "网格型"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
Selection.Tables(1).Select
Selection.Borders(wdBorderTop).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderRight).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
Selection.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Tables(1).Select
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="第"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:="=2*"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
Selection.TypeText Text:="-1"
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="页,共"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:="=2*"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldNumPages
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="页"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="第"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:="=2*"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="页,共"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:="=2*"
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldNumPages
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="页"
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes
ActiveWindow.View.TableGridlines = Not ActiveWindow.View.TableGridlines
End Sub |
|