透過 ParagraphFormat 物件可精確控制段落所有屬性,以下為完整設定範例(以 C# 風格語法呈現):
// 段落格式設定
WApp.Selection.ParagraphFormat.LeftIndent = WApp.CentimetersToPoints(0) ' 左縮進
WApp.Selection.ParagraphFormat.RightIndent = WApp.CentimetersToPoints(0) ' 右縮進
WApp.Selection.ParagraphFormat.SpaceBefore = 0 ' 段前間距
WApp.Selection.ParagraphFormat.SpaceBeforeAuto = 0 ' 自動段前間距
WApp.Selection.ParagraphFormat.SpaceAfter = 0 ' 段後間距
WApp.Selection.ParagraphFormat.SpaceAfterAuto = 0 ' 自動段後間距
WApp.Selection.ParagraphFormat.LineSpacingRule = wdLineSpaceSingle ' 行距:單倍
WApp.Selection.ParagraphFormat.Alignment = wdAlignParagraphJustify ' 對齊:兩端對齊
WApp.Selection.ParagraphFormat.WidowControl = 0 ' 孤行控制
WApp.Selection.ParagraphFormat.KeepWithNext = 0 ' 與下段同頁
WApp.Selection.ParagraphFormat.KeepTogether = 0 ' 段中不分頁
WApp.Selection.ParagraphFormat.PageBreakBefore = 0 ' 段前分頁
WApp.Selection.ParagraphFormat.NoLineNumber = 0 ' 取消行號
WApp.Selection.ParagraphFormat.Hyphenation = 1 ' 取消斷字
WApp.Selection.ParagraphFormat.FirstLineIndent = WApp.CentimetersToPoints(0) ' 首行縮進
WApp.Selection.ParagraphFormat.OutlineLevel = wdOutlineLevelBodyText ' 大綱層級:正文
WApp.Selection.ParagraphFormat.CharacterUnitLeftIndent = 0 ' 字元單位左縮進
WApp.Selection.ParagraphFormat.CharacterUnitRightIndent = 0 ' 字元單位右縮進
WApp.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = 0 ' 字元單位首行縮進
WApp.Selection.ParagraphFormat.LineUnitBefore = 0 ' 行單位段前間距
WApp.Selection.ParagraphFormat.LineUnitAfter = 0 ' 行單位段後間距
WApp.Selection.ParagraphFormat.AutoAdjustRightIndent = 1 ' 自動調整右縮進
WApp.Selection.ParagraphFormat.DisableLineHeightGrid = 0 ' 禁用行高網格
WApp.Selection.ParagraphFormat.FarEastLineBreakControl = 1 ' 東亞斷行控制
WApp.Selection.ParagraphFormat.WordWrap = 1 ' 自動換行
WApp.Selection.ParagraphFormat.HangingPunctuation = 1 ' 懸掛標點
WApp.Selection.ParagraphFormat.HalfWidthPunctuationOnTopOfLine = 0 ' 半寬標點不壓行首
WApp.Selection.ParagraphFormat.AddSpaceBetweenFarEastAndAlpha = 1 ' 東亞與英數間自動加空格
WApp.Selection.ParagraphFormat.AddSpaceBetweenFarEastAndDigit = 1 ' 東亞與數字間自動加空格
WApp.Selection.ParagraphFormat.BaseLineAlignment = wdBaselineAlignAuto ' 基準線對齊:自動
重點屬性說明:
LeftIndent、RightIndent、FirstLineIndent(首行)、CharacterUnit*(以字元為單位)。SpaceBefore/After(點)、SpaceBeforeAuto/AfterAuto(自動)、LineUnitBefore/After(行)。LineSpacingRule 可設單倍、1.5倍、雙倍、最小值、固定值、多倍。WidowControl(孤行)、KeepWithNext(與下段同頁)、KeepTogether(段不分頁)、PageBreakBefore(段前分頁)。FarEastLineBreakControl、WordWrap、HangingPunctuation、HalfWidthPunctuationOnTopOfLine、AddSpaceBetweenFarEastAndAlpha/Digit。BaseLineAlignment 用於網格對齊時的字元基準線設定。此範例涵蓋段落格式幾乎所有屬性,可作為 VBA 批次排版、樣式建立的參考範本。