利⽤word的VBA,为代码统⼀表格宽度,底⾊及⾏号
如果⽂档中的代码表格时,感觉还是很快速有⽤的。
Sub HangHao()
'
' hanghao 宏
'
'
Dim parag As Paragraph
Dim nLineNum: nLineNum = 0
Dim selRge As Range
Set selRge = Selection.Range
For Each parag In Selection.Paragraphs
nLineNum = nLineNum + 1 bgNLineNum = nLineNum selRge.Paragraphs(nLineNum).Range.InsertBefore (Format$(bgNLineNum, "00") & " ") Next ' 背景⾊为morning的配⾊⽅案,RGB为(229,229,229) With Selection.Tables(1) With .Shading .Texture = wdTextureNone .ForegroundPatternColor = wdColorAutomatic .BackgroundPatternColor = 15066597 '15066597这个数其实就是229*(2^16 + 2^8 + 1) End With Options.DefaultHighlightColorIndex = wdNoHighlight 'NeXT_Jobs新增的:清除“以不同颜⾊突出显⽰⽂本”,从⽽解决从VS中“保留源格式”复制带来的⽂本⾼亮问题
Selection.Range.HighlightColorIndex = wdNoHighlight 'NeXT_Jobs新增的:清除“以不同颜⾊突出显⽰⽂本”,从⽽解决从VS中“保留源格式”复制带来的⽂本⾼亮问题 .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 End With Wi
th Options .DefaultBorderLineStyle = wdLineStyleSingle .DefaultBorderLineWidth = wdLineWidth050pt .DefaultBorderColor = wdColorAutomatic End With ' 段落⽆⾸⾏缩进,⾏间距为固定值12磅 With Selection.ParagraphFormat .LeftIndent = CentimetersToPoints(0) .RightIndent = CentimetersToPoints(0) .SpaceBefore = 0 .SpaceBeforeAuto = False .SpaceAfter = 0 .SpaceAfterAuto = False .LineSpacingRule = wdLineSpaceExactly '⾏距为“固定值” .LineSpacing = 16 '⾏距为“固定值”的“12磅” .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 .MirrorIndents = False .TextboxTightWrap = wdTightNone .AutoAdjustRightIndent = True .DisableLineHeightGrid = False .FarEastLineBreakControl = True .WordWrap = True .HangingPunctuation = True .HalfWidthPunctuationOnTopOfLine = False .AddSpaceBetweenFarEastAndAlpha = Truehtmlborder
.AddSpaceBetweenFarEastAndDigit = True .BaseLineAlignment = wdBaselineAlignAuto End With ' 清除原有的段落底纹
Selection.ParagraphFormat.Shading.BackgroundPatternColor = wdColorAutomatic End Sub Sub tab
le_100() ' ' table_100 宏 ' ' Dim tempTable As Table Application.ScreenUpdating = False '判断⽂档是否被保护 If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then MsgBox "⽂档已保护,此时不能选中多个表格!" Exit Sub End If '删除所有可编辑的区域 ActiveDocument.DeleteAllEditableRanges wdEditorEveryone '添加可编辑区域 For Each tempTable In ActiveDocument.Tables tempTable.Range.Editors.Add wdEditorEveryone tempTable.PreferredWidthType = wdPreferredWidthPercent tempTable.PreferredWidth = 100 Next '选中所有可编辑区域 ActiveDocument.SelectAllEditableRanges wdEditorEveryone '删除所有可编辑的区域ActiveDocument.DeleteAllEditableRanges wdEditorEveryone Application.ScreenUpdating = True End Sub
来个效果:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论