码迷,mamicode.com
首页 > 其他好文 > 详细

Word 脚本 (自用)

时间:2020-07-10 13:26:46      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:pac   nes   点击   关闭   lazy   app   update   head   sele   

打开开发工具

右击功能区->自定义功能区

技术图片

勾选开发工具->确定

技术图片

导入代码

开发工具选项卡->Visual Basic

技术图片

右击Normal->插入->模块

技术图片

粘贴代码->ctrl+s 保存

Sub 修改样式()
     
    ‘ 八号磅值5
    ‘ 七号磅值5.5
    ‘ 小六磅值6.5 六号磅值7.5
    ‘ 小五磅值9 五号磅值10.5
    ‘ 小四磅值12 四号磅值14
    ‘ 小三磅值15 三号磅值16
    ‘ 小二磅值18 二号磅值22
    ‘ 小一磅值24 一号磅值26
    ‘ 小初磅值36 初号磅值42

    ‘ 删除用户所有自定义样式
    For Each sty In ActiveDocument.Styles
     If sty.BuiltIn = False Then sty.Delete
    Next sty

    ‘标题1样式
    With ActiveDocument.Styles(wdStyleHeading1).Font
        .Color = wdColorAutomatic
        .NameFarEast = "宋体"
        .NameAscii = "Times New Roman"
        .Size = 16  ‘字号,请输入对应数字
        .Bold = 1 ‘加粗为1,不加粗为0
    End With
    With ActiveDocument.Styles(wdStyleHeading1).ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .Alignment = wdAlignParagraphCenter ‘ 居中对齐
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0.5  ‘段前为0.5行
        .LineUnitAfter = 0.5 ‘段后为0.5行
        .LineSpacingRule = wdLineSpaceExactly
        .LineSpacing = 17
    End With
    
    ‘标题2样式
    With ActiveDocument.Styles(wdStyleHeading2).Font
        .Color = wdColorAutomatic
        .NameFarEast = "宋体"
        .NameAscii = "Times New Roman"
        .Size = 14  ‘字号,请输入对应数字
        .Bold = 1 ‘加粗为1,不加粗为0
    End With
    With ActiveDocument.Styles(wdStyleHeading2).ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .Alignment = wdAlignParagraphJustify
        .CharacterUnitFirstLineIndent = 0  ‘ 首行缩进0字符
        .LineUnitBefore = 0.5
        .LineUnitAfter = 0.5
        .LineSpacingRule = wdLineSpaceExactly
        .LineSpacing = 17
    End With
    
    ‘标题3样式
    With ActiveDocument.Styles(wdStyleHeading3).Font
        .Color = wdColorAutomatic
        .NameFarEast = "宋体"
        .NameAscii = "Times New Roman"
        .Size = 14  ‘字号,请输入对应数字
        .Bold = 1 ‘加粗为1,不加粗为0
    End With
    With ActiveDocument.Styles(wdStyleHeading3).ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .Alignment = wdAlignParagraphJustify
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .LineSpacingRule = wdLineSpaceExactly
        .LineSpacing = 17
    End With
    
    ‘标题4样式
    With ActiveDocument.Styles(wdStyleHeading4).Font
        .Color = wdColorAutomatic
        .NameFarEast = "宋体"
        .NameAscii = "Times New Roman"
        .Size = 14  ‘字号,请输入对应数字
        .Bold = 1 ‘加粗为1,不加粗为0
    End With
    With ActiveDocument.Styles(wdStyleHeading4).ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .Alignment = wdAlignParagraphJustify
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .LineSpacingRule = wdLineSpaceExactly
        .LineSpacing = 17
    End With
    
    ‘标题5样式
    With ActiveDocument.Styles(wdStyleHeading5).Font
        .Color = wdColorAutomatic
        .NameFarEast = "宋体"
        .NameAscii = "Times New Roman"
        .Size = 14  ‘字号,请输入对应数字
        .Bold = 1 ‘加粗为1,不加粗为0
    End With
    With ActiveDocument.Styles(wdStyleHeading4).ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .Alignment = wdAlignParagraphJustify
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .LineSpacingRule = wdLineSpaceExactly
        .LineSpacing = 17
    End With
    
    ‘ 正文样式
    With ActiveDocument.Styles("正文").Font
        .Color = wdColorAutomatic
        .NameFarEast = "宋体"
        .NameAscii = "Times New Roman"
        .Size = 12  ‘字号,请输入对应数字
        .Bold = 0 ‘加粗为1,不加粗为0
    End With
    With ActiveDocument.Styles(wdStyleHeading4).ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .Alignment = wdAlignParagraphJustify
        .CharacterUnitFirstLineIndent = 2
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .LineSpacingRule = wdLineSpaceExactly
        .LineSpacing = 17
    End With
    
    ‘ 图标表
    Application.ScreenUpdating = False ‘关闭屏幕更新
    ActiveDocument.Styles.Add Name:="图标表", Type:=wdStyleTypeParagraph
    ActiveDocument.Styles("图标表").AutomaticallyUpdate = False
    With ActiveDocument.Styles("图标表").Font
        .Color = wdColorAutomatic
        .NameFarEast = "楷体"
        .NameAscii = "Times New Roman"
        .Size = 10.5  ‘字号,请输入对应数字
        .Bold = 0 ‘加粗为1,不加粗为0
    End With
    With ActiveDocument.Styles("图标表").ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .Alignment = wdAlignParagraphCenter
        ‘.CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0.5
        .LineUnitAfter = 0.5
        .OutlineLevel = wdOutlineLevelBodyText ‘ 大纲级别普通文本
        .LineSpacingRule = wdLineSpaceSingle
    End With

End Sub

Sub 设置图标表()
    Selection.Style = "图标表"
End Sub

自定义功能

右击功能区->自定义功能区

技术图片

点击开始->新建组->点击刚创建的组->重命名

技术图片

点击自定义样式->选择宏->选择相应的函数->添加->选择刚添加的函数->重命名并设置图标

技术图片

完工

最后点击相应的相应的样式,便可应用及自动产生大纲级别

技术图片

Word 脚本 (自用)

标签:pac   nes   点击   关闭   lazy   app   update   head   sele   

原文地址:https://www.cnblogs.com/hemou/p/13278602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!