【WORD VBA】常用排版|段落設定|字體調整|蜂巢式標題內文設定|表格加框線
Sub 基本排版()
‘聲明 Sel 為 Selection
Dim Sel As Word.Selection
Set Sel = Selection ‘實例化Sel
Sel.WholeStory ‘全選整個檔案內容
Sel.ClearFormatting ‘清除所選文字格式
‘【常用段落的排版設置】
‘聲明ParFor為ParagraphFormat
Dim ParFor As ParagraphFormat
Set ParFor = Sel.ParagraphFormat
ParFor.Alignment = 3 ‘兩端對齊
‘【常用字體的設置】
Sel.Font.Size = 12 ‘設置12pt字體
Sel.Font.Name = “標楷體” ‘設置標楷體字體
Sel.Font.Name = ” times new roman” ‘設置times new roman字體
End Sub
Sub 壹段落標題()
‘聲明 Sel 為 Selection
Dim Sel As Word.Selection
Set Sel = Selection ‘實例化Sel
Sel.ClearFormatting ‘清除所選文本格式
‘【常用段落的排版設置】
‘聲明ParFor為ParagraphFormat
Dim ParFor As ParagraphFormat
Set ParFor = Sel.ParagraphFormat
Sel.Expand 4 ‘選取當前這段
ParFor.Alignment = 3 ‘兩端對齊
ParFor.CharacterUnitFirstLineIndent = -2 ‘懸掛縮進
ParFor.LineSpacing = 12 ‘自定義行距
ParFor.LineUnitBefore = 0.5 ‘距前段0.5行
ParFor.LineUnitAfter = 0 ‘距前段0行
‘【常用字體的設置】
Sel.Font.Size = 12 ‘設置12pt字體
Sel.Font.Name = “標楷體” ‘設置標楷體字體
Sel.Font.Name = ” times new roman” ‘設置times new roman字體
Sel.Font.Bold = True ‘加粗
Sel.Range.HighlightColorIndex = wdNoHighlight ‘取消醒目提醒
End Sub
Sub 壹一段落內文()
‘聲明 Sel 為 Selection
Dim Sel As Word.Selection
Set Sel = Selection ‘實例化Sel
Sel.ClearFormatting ‘清除所選文本格式
‘【常用段落的排版設置】
‘聲明ParFor為ParagraphFormat
Dim ParFor As ParagraphFormat
Set ParFor = Sel.ParagraphFormat
Sel.Expand 4 ‘選取當前這段
ParFor.Alignment = 3 ‘兩端對齊
ParFor.CharacterUnitLeftIndent = 2 ‘段落左縮進
ParFor.CharacterUnitFirstLineIndent = 2 ‘首行縮進
ParFor.LineSpacing = 12 ‘自定義行距
ParFor.LineUnitBefore = 0.5 ‘距前段0.5行
ParFor.LineUnitAfter = 0 ‘距前段0行
‘【常用字體的設置】
Sel.Font.Size = 12 ‘設置12pt字體
Sel.Font.Name = “標楷體” ‘設置標楷體字體
Sel.Font.Name = ” times new roman” ‘設置times new roman字體
Sel.Range.HighlightColorIndex = wdNoHighlight ‘取消醒目提醒
End Sub
Sub 一段落標題()
‘聲明 Sel 為 Selection
Dim Sel As Word.Selection
Set Sel = Selection ‘實例化Sel
Sel.ClearFormatting ‘清除所選文本格式
‘【常用段落的排版設置】
‘聲明ParFor為ParagraphFormat
Dim ParFor As ParagraphFormat
Set ParFor = Sel.ParagraphFormat
Sel.Expand 4 ‘選取當前這段
ParFor.Alignment = 3 ‘兩端對齊
ParFor.CharacterUnitFirstLineIndent = -2 ‘懸掛縮進
ParFor.LineSpacing = 12 ‘自定義行距
ParFor.LineUnitBefore = 0.5 ‘距前段0.5行
ParFor.LineUnitAfter = 0 ‘距前段0行
‘【常用字體的設置】
Sel.Font.Size = 12 ‘設置12pt字體
Sel.Font.Name = “標楷體” ‘設置標楷體字體
Sel.Font.Name = ” times new roman” ‘設置times new roman字體
Sel.Range.HighlightColorIndex = wdNoHighlight ‘取消醒目提醒
End Sub
Sub 括弧一標題()
‘聲明 Sel 為 Selection
Dim Sel As Word.Selection
Set Sel = Selection ‘實例化Sel
Sel.ClearFormatting ‘清除所選文本格式
‘【常用段落的排版設置】
‘聲明ParFor為ParagraphFormat
Dim ParFor As ParagraphFormat
Set ParFor = Sel.ParagraphFormat
Sel.Expand 4 ‘選取當前這段
ParFor.Alignment = 3 ‘兩端對齊
ParFor.CharacterUnitLeftIndent = 2 ‘段落左縮進(重點差別)
ParFor.CharacterUnitFirstLineIndent = -2 ‘懸掛縮進
ParFor.LineSpacing = 12 ‘自定義行距
ParFor.LineUnitBefore = 0.5 ‘距前段0.5行
ParFor.LineUnitAfter = 0 ‘距前段0行
‘【常用字體的設置】
Sel.Font.Size = 12 ‘設置12pt字體
Sel.Font.Name = “標楷體” ‘設置標楷體字體
Sel.Font.Name = ” times new roman” ‘設置times new roman字體
Sel.Range.HighlightColorIndex = wdNoHighlight ‘取消醒目提醒
End Sub
Sub 括弧一內文()
‘聲明 Sel 為 Selection
Dim Sel As Word.Selection
Set Sel = Selection ‘實例化Sel
Sel.ClearFormatting ‘清除所選文本格式
‘【常用段落的排版設置】
‘聲明ParFor為ParagraphFormat
Dim ParFor As ParagraphFormat
Set ParFor = Sel.ParagraphFormat
Sel.Expand 4 ‘選取當前這段
ParFor.Alignment = 3 ‘兩端對齊
ParFor.CharacterUnitLeftIndent = 4 ‘段落左縮進(重點差別)
ParFor.CharacterUnitFirstLineIndent = 2 ‘首行縮進
ParFor.LineSpacing = 12 ‘自定義行距
ParFor.LineUnitBefore = 0.5 ‘距前段0.5行
ParFor.LineUnitAfter = 0 ‘距前段0行
‘【常用字體的設置】
Sel.Font.Size = 12 ‘設置12pt字體
Sel.Font.Name = “標楷體” ‘設置標楷體字體
Sel.Font.Name = ” times new roman” ‘設置times new roman字體
Sel.Range.HighlightColorIndex = wdNoHighlight ‘取消醒目提醒
End Sub
Sub 數字1標題()
‘聲明 Sel 為 Selection
Dim Sel As Word.Selection
Set Sel = Selection ‘實例化Sel
Sel.ClearFormatting ‘清除所選文本格式
‘【常用段落的排版設置】
‘聲明ParFor為ParagraphFormat
Dim ParFor As ParagraphFormat
Set ParFor = Sel.ParagraphFormat
Sel.Expand 4 ‘選取當前這段
ParFor.Alignment = 3 ‘兩端對齊
ParFor.CharacterUnitLeftIndent = 4 ‘段落左縮進(重點差別)
ParFor.CharacterUnitFirstLineIndent = -0.8 ‘懸掛縮進(重點差別)
ParFor.LineSpacing = 12 ‘自定義行距
ParFor.LineUnitBefore = 0.5 ‘距前段0.5行
ParFor.LineUnitAfter = 0 ‘距前段0行
‘【常用字體的設置】
Sel.Font.Size = 12 ‘設置12pt字體
Sel.Font.Name = “標楷體” ‘設置標楷體字體
Sel.Font.Name = ” times new roman” ‘設置times new roman字體
Sel.Range.HighlightColorIndex = wdNoHighlight ‘取消醒目提醒
End Sub
Sub 數字1內文()
‘聲明 Sel 為 Selection
Dim Sel As Word.Selection
Set Sel = Selection ‘實例化Sel
Sel.ClearFormatting ‘清除所選文本格式
‘【常用段落的排版設置】
‘聲明ParFor為ParagraphFormat
Dim ParFor As ParagraphFormat
Set ParFor = Sel.ParagraphFormat
Sel.Expand 4 ‘選取當前這段
ParFor.Alignment = 3 ‘兩端對齊
ParFor.CharacterUnitLeftIndent = 5 ‘段落左縮進(重點差別)
ParFor.CharacterUnitFirstLineIndent = 2 ‘首行縮進
ParFor.LineSpacing = 12 ‘自定義行距
ParFor.LineUnitBefore = 0.5 ‘距前段0.5行
ParFor.LineUnitAfter = 0 ‘距前段0行
‘【常用字體的設置】
Sel.Font.Size = 12 ‘設置12pt字體
Sel.Font.Name = “標楷體” ‘設置標楷體字體
Sel.Font.Name = ” times new roman” ‘設置times new roman字體
Sel.Range.HighlightColorIndex = wdNoHighlight ‘取消醒目提醒
End Sub
Sub 括號數字1標題()
‘聲明 Sel 為 Selection
Dim Sel As Word.Selection
Set Sel = Selection ‘實例化Sel
Sel.ClearFormatting ‘清除所選文本格式
‘【常用段落的排版設置】
‘聲明ParFor為ParagraphFormat
Dim ParFor As ParagraphFormat
Set ParFor = Sel.ParagraphFormat
Sel.Expand 4 ‘選取當前這段
ParFor.Alignment = 3 ‘兩端對齊
ParFor.CharacterUnitLeftIndent = 5 ‘段落左縮進(重點差別)
ParFor.CharacterUnitFirstLineIndent = -1.2 ‘懸掛縮進(重點差別)
ParFor.LineSpacing = 12 ‘自定義行距
ParFor.LineUnitBefore = 0.5 ‘距前段0.5行
ParFor.LineUnitAfter = 0 ‘距前段0行
‘【常用字體的設置】
Sel.Font.Size = 12 ‘設置12pt字體
Sel.Font.Name = “標楷體” ‘設置標楷體字體
Sel.Font.Name = ” times new roman” ‘設置times new roman字體
Sel.Range.HighlightColorIndex = wdNoHighlight ‘取消醒目提醒
End Sub
Sub 括號數字1內文()
‘聲明 Sel 為 Selection
Dim Sel As Word.Selection
Set Sel = Selection ‘實例化Sel
Sel.ClearFormatting ‘清除所選文本格式
‘【常用段落的排版設置】
‘聲明ParFor為ParagraphFormat
Dim ParFor As ParagraphFormat
Set ParFor = Sel.ParagraphFormat
Sel.Expand 4 ‘選取當前這段
ParFor.Alignment = 3 ‘兩端對齊
ParFor.CharacterUnitLeftIndent = 6.2 ‘段落左縮進(重點差別)
ParFor.CharacterUnitFirstLineIndent = 2 ‘首行縮進
ParFor.LineSpacing = 12 ‘自定義行距
ParFor.LineUnitBefore = 0.5 ‘距前段0.5行
ParFor.LineUnitAfter = 0 ‘距前段0行
‘【常用字體的設置】
Sel.Font.Size = 12 ‘設置12pt字體
Sel.Font.Name = “標楷體” ‘設置標楷體字體
Sel.Font.Name = ” times new roman” ‘設置times new roman字體
Sel.Range.HighlightColorIndex = wdNoHighlight ‘取消醒目提醒
End Sub
Sub A標題()
‘聲明 Sel 為 Selection
Dim Sel As Word.Selection
Set Sel = Selection ‘實例化Sel
Sel.ClearFormatting ‘清除所選文本格式
‘【常用段落的排版設置】
‘聲明ParFor為ParagraphFormat
Dim ParFor As ParagraphFormat
Set ParFor = Sel.ParagraphFormat
Sel.Expand 4 ‘選取當前這段
ParFor.Alignment = 3 ‘兩端對齊
ParFor.CharacterUnitLeftIndent = 6 ‘段落左縮進(重點差別)
ParFor.CharacterUnitFirstLineIndent = -1 ‘懸掛縮進(重點差別)
ParFor.LineSpacing = 12 ‘自定義行距
ParFor.LineUnitBefore = 0.5 ‘距前段0.5行
ParFor.LineUnitAfter = 0 ‘距前段0行
‘【常用字體的設置】
Sel.Font.Size = 12 ‘設置12pt字體
Sel.Font.Name = “標楷體” ‘設置標楷體字體
Sel.Font.Name = ” times new roman” ‘設置times new roman字體
Sel.Range.HighlightColorIndex = wdNoHighlight ‘取消醒目提醒
End Sub
Sub A內文()
‘聲明 Sel 為 Selection
Dim Sel As Word.Selection
Set Sel = Selection ‘實例化Sel
Sel.ClearFormatting ‘清除所選文本格式
‘【常用段落的排版設置】
‘聲明ParFor為ParagraphFormat
Dim ParFor As ParagraphFormat
Set ParFor = Sel.ParagraphFormat
Sel.Expand 4 ‘選取當前這段
ParFor.Alignment = 3 ‘兩端對齊
ParFor.CharacterUnitLeftIndent = 7 ‘段落左縮進(重點差別)
ParFor.CharacterUnitFirstLineIndent = 2 ‘首行縮進
ParFor.LineSpacing = 12 ‘自定義行距
ParFor.LineUnitBefore = 0.5 ‘距前段0.5行
ParFor.LineUnitAfter = 0 ‘距前段0行
‘【常用字體的設置】
Sel.Font.Size = 12 ‘設置12pt字體
Sel.Font.Name = “標楷體” ‘設置標楷體字體
Sel.Font.Name = ” times new roman” ‘設置times new roman字體
Sel.Range.HighlightColorIndex = wdNoHighlight ‘取消醒目提醒
End Sub
Sub 小A標題()
‘聲明 Sel 為 Selection
Dim Sel As Word.Selection
Set Sel = Selection ‘實例化Sel
Sel.ClearFormatting ‘清除所選文本格式
‘【常用段落的排版設置】
‘聲明ParFor為ParagraphFormat
Dim ParFor As ParagraphFormat
Set ParFor = Sel.ParagraphFormat
Sel.Expand 4 ‘選取當前這段
ParFor.Alignment = 3 ‘兩端對齊
ParFor.CharacterUnitLeftIndent = 7 ‘段落左縮進(重點差別)
ParFor.CharacterUnitFirstLineIndent = -0.8 ‘懸掛縮進(重點差別)
ParFor.LineSpacing = 12 ‘自定義行距
ParFor.LineUnitBefore = 0.5 ‘距前段0.5行
ParFor.LineUnitAfter = 0 ‘距前段0行
‘【常用字體的設置】
Sel.Font.Size = 12 ‘設置12pt字體
Sel.Font.Name = “標楷體” ‘設置標楷體字體
Sel.Font.Name = ” times new roman” ‘設置times new roman字體
Sel.Range.HighlightColorIndex = wdNoHighlight ‘取消醒目提醒
End Sub
Sub 表格加外框()
Set mytable = ActiveDocument.Tables(1)
With mytable.Borders
.OutsideLineStyle = wdLineStyleSingle
.OutsideLineWidth = wdLineWidth150pt
.DistanceFromBottom = 0
.DistanceFromTop = 0
.DistanceFromLeft = 2
.DistanceFromRight = 2
End With
End Sub