如果文档中的代码表格时,感觉还是很快速有用的。

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
    With 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 = True
        .AddSpaceBetweenFarEastAndDigit = True
        .BaseLineAlignment = wdBaselineAlignAuto
    End With
    ' 清除原有的段落底纹
    Selection.ParagraphFormat.Shading.BackgroundPatternColor = wdColorAutomatic

End Sub
Sub table_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

来个效果:

最新文章

  1. Chart: Who pays the most in Seattle for software engineers
  2. webservice客户端添加soap Header信息
  3. go 数组(array)、切片(slice)、map、结构体(struct)
  4. translate和replace的区别
  5. poj 1797(并查集)
  6. EXCEL中讲 10分10秒转换成610秒
  7. Visual Studio 2017 Bugs
  8. Dive in python Chapter3 实例
  9. idea+springmvc+spring+mybatis+maven整合返回json数据webapi
  10. 总结一下现在关于Design Support Library的几个博客
  11. ubuntu Emergency Mode
  12. ZJOI 2019 游记
  13. Codeforces 959F Mahmoud and Ehab and yet another xor task 线性基 (看题解)
  14. Android Studio 签名 安全图片
  15. Java JDK下载、安装与环境变量配置
  16. MySQL基本教程(一)
  17. Bootstrap缩略图
  18. cocos2d JS 在 JavaScript 中,怎样把一个对象转化成 JSON 字符串?
  19. c++、Java、python对应的编译型语言和解释性语言区别详解
  20. 八大排序算法的Java代码实现

热门文章

  1. Codeforces 494C - Helping People
  2. Java字节流与字符流
  3. Warm up HDU - 4612( 树的直径 边双连通分量)
  4. Minimum Sum LCM UVA - 10791(分解质因子)
  5. SpringBoot中的定时任务与Quartz的整合
  6. Android Service总结05 之IntentService
  7. emoji表情与unicode编码互转(JS,JAVA,C#)
  8. 20181108 Apache Commons Lang
  9. 小贾漫谈——Java反射
  10. POJ 3710 无向图简单环树上删边