Word 腳本 (自用)


打開開發工具

右擊功能區->自定義功能區

image-20200710113152652

勾選開發工具->確定

image-20200710113231101

導入代碼

開發工具選項卡->Visual Basic

image-20200710113359241

右擊Normal->插入->模塊

image-20200710113455705

粘貼代碼->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 = 23
    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 = 23
    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 = 23
    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 = 23
    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(wdStyleHeading5).ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .Alignment = wdAlignParagraphJustify
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .LineSpacingRule = wdLineSpaceExactly
        .LineSpacing = 23
    End With
    
    ' 正文樣式
    With ActiveDocument.Styles("正文").Font
        .Color = wdColorAutomatic
        .NameFarEast = "宋體"
        .NameAscii = "Times New Roman"
        .Size = 12  '字號,請輸入對應數字
        .Bold = 0 '加粗為1,不加粗為0
    End With
    With ActiveDocument.Styles("正文").ParagraphFormat
        .LeftIndent = CentimetersToPoints(0)
        .Alignment = wdAlignParagraphJustify
        .CharacterUnitFirstLineIndent = 2
        .LineUnitBefore = 0  '段前為0.8行
        .LineUnitAfter = 0 '段后為0.5行
        .LineSpacingRule = wdLineSpaceExactly
        .LineSpacing = 23
    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

自定義功能

右擊功能區->自定義功能區

image-20200710113152652

點擊開始->新建組->點擊剛創建的組->重命名

image-20200710115351086

點擊自定義樣式->選擇宏->選擇相應的函數->添加->選擇剛添加的函數->重命名並設置圖標

image-20200710115628177

完工

最后點擊相應的相應的樣式,便可應用及自動產生大綱級別

image-20200710120142286


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM