1、宏的代码如下。

Sub 设置代码表格()
' author: code4101
' 设置代码表格 宏
'
'
' 背景色为morning的配色方案,RGB为(229,229,229)
With Selection.Tables()
With .Shading
.Texture = wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor =
End With
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
.AutoFitBehavior (wdAutoFitContent) '自动调整大小
End With
With Options
.DefaultBorderLineStyle = wdLineStyleSingle
.DefaultBorderLineWidth = wdLineWidth050pt
.DefaultBorderColor = wdColorAutomatic
End With ' 段落无首行缩进,行间距为固定值12磅
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints()
.RightIndent = CentimetersToPoints()
.SpaceBefore =
.SpaceBeforeAuto = False
.SpaceAfter =
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceExactly
.LineSpacing =
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = CentimetersToPoints()
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent =
.CharacterUnitRightIndent =
.CharacterUnitFirstLineIndent =
.LineUnitBefore =
.LineUnitAfter =
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
.AutoAdjustRightIndent = True
.DisableLineHeightGrid = False
.FarEastLineBreakControl = True
.WordWrap = True
.HangingPunctuation = True
.HalfWidthPunctuationOnTopOfLine = False
.AddSpaceBetweenFarEastAndAlpha = True
.AddSpaceBetweenFarEastAndDigit = True
.BaseLineAlignment = wdBaselineAlignAuto
End With
' 清除原有的段落底纹
Selection.ParagraphFormat.Shading.BackgroundPatternColor = wdColorAutomatic
End Sub Sub 输入连续数字()
' author: code4101
行数 = InputBox("请输入代码终止行数", "输入行数", "")
For i = To 行数 -
Selection.TypeText Text:=i
Selection.TypeParagraph
Next
Selection.TypeText Text:=行数
End Sub

2、新建一个2行1列的表格  进行调用宏。

05-11 21:58