萬盛學電腦網

 萬盛學電腦網 >> WORD教程 >> WORD使用技巧 >> Vba全面修改Word段落屬性有效代碼

Vba全面修改Word段落屬性有效代碼

  下面的WAPP是事先定義的word文檔工程變量。

  以下代碼為通過VBA代碼修改Word段落的縮進、段落間距、行距、分頁等。

  //段落格式設定

  WApp.Selection.ParagraphFormat.LeftIndent = WApp.CentimetersToPoints(float.Parse("0"));//左縮進

  WApp.Selection.ParagraphFormat.RightIndent = WApp.CentimetersToPoints(float.Parse("0"));//右縮進

  WApp.Selection.ParagraphFormat.SpaceBefore =float.Parse("0");//段前間距

  WApp.Selection.ParagraphFormat.SpaceBeforeAuto =0;//

  WApp.Selection.ParagraphFormat.SpaceAfter = float.Parse("0");//段後間距

  WApp.Selection.ParagraphFormat.SpaceAfterAuto = 0;//

  WApp.Selection.ParagraphFormat.LineSpacingRule = Microsoft.Office.Interop.Word.WdLineSpacing.wdLineSpaceSingle;//單倍行距

  WApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphJustify;//段落2端對齊

  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(float.Parse("0"));//首行縮進

  WApp.Selection.ParagraphFormat.OutlineLevel = Microsoft.Office.Interop.Word.WdOutlineLevel.wdOutlineLevelBodyText;

  WApp.Selection.ParagraphFormat.CharacterUnitLeftIndent = float.Parse("0");

  WApp.Selection.ParagraphFormat.CharacterUnitRightIndent = float.Parse("0");

  WApp.Selection.ParagraphFormat.CharacterUnitFirstLineIndent = float.Parse("0");

  WApp.Selection.ParagraphFormat.LineUnitBefore = float.Parse("0");

  WApp.Selection.ParagraphFormat.LineUnitAfter = float.Parse("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 = Microsoft.Office.Interop.Word.WdBaselineAlignment.wdBaselineAlignAuto;

copyright © 萬盛學電腦網 all rights reserved