2014-05-01 23 views
4

我试图以编程方式更改“不要在同一样式的段落之间添加空格”。为了解决这个问题,我录制了一个宏,在此期间,我打开了段落对话框(页面布局>段落),选中了复选框(不添加空格)和一个宏,在此期间我取消选中复选框(添加空格)。不会影响“不要在相同样式的段落之间添加空格”。 。 。他们有相同的代码:如何以编程方式更改“不要在相同样式的段落之间添加空格”?

Sub AddSpaceBetweenParagraphsOfSameStyle() 
' 
' AddSpaceBetweenParagraphsOfSameStyle Macro 
' Add space between paragraphs of the same style. 
' 
    With Selection.ParagraphFormat 
     .LeftIndent = InchesToPoints(0.5) 
     .RightIndent = InchesToPoints(0) 
     .SpaceBefore = 12 
     .SpaceBeforeAuto = False 
     .SpaceAfter = 12 
     .SpaceAfterAuto = False 
     .LineSpacingRule = wdLineSpaceMultiple 
     .LineSpacing = LinesToPoints(1) 
     .Alignment = wdAlignParagraphLeft 
     .WidowControl = True 
     .KeepWithNext = False 
     .KeepTogether = False 
     .PageBreakBefore = False 
     .NoLineNumber = False 
     .Hyphenation = True 
     .FirstLineIndent = InchesToPoints(-0.25) 
     .OutlineLevel = wdOutlineLevelBodyText 
     .CharacterUnitLeftIndent = 0 
     .CharacterUnitRightIndent = 0 
     .CharacterUnitFirstLineIndent = 0 
     .LineUnitBefore = 0 
     .LineUnitAfter = 0 
     .MirrorIndents = False 
     .TextboxTightWrap = wdTightNone 
    End With 
End Sub 

Sub RemoveSpaceBetweenParagraphsOfSameStyle() 
' 
' RemoveSpaceBetweenParagraphsOfSameStyle Macro 
' Remove space between paragraphs of the same style. 
' 
    With Selection.ParagraphFormat 
     .LeftIndent = InchesToPoints(0.5) 
     .RightIndent = InchesToPoints(0) 
     .SpaceBefore = 12 
     .SpaceBeforeAuto = False 
     .SpaceAfter = 12 
     .SpaceAfterAuto = False 
     .LineSpacingRule = wdLineSpaceMultiple 
     .LineSpacing = LinesToPoints(1) 
     .Alignment = wdAlignParagraphLeft 
     .WidowControl = True 
     .KeepWithNext = False 
     .KeepTogether = False 
     .PageBreakBefore = False 
     .NoLineNumber = False 
     .Hyphenation = True 
     .FirstLineIndent = InchesToPoints(-0.25) 
     .OutlineLevel = wdOutlineLevelBodyText 
     .CharacterUnitLeftIndent = 0 
     .CharacterUnitRightIndent = 0 
     .CharacterUnitFirstLineIndent = 0 
     .LineUnitBefore = 0 
     .LineUnitAfter = 0 
     .MirrorIndents = False 
     .TextboxTightWrap = wdTightNone 
    End With 
End Sub 

由宏录制生成的代码很长,所以我把它减少到我已经验证也没有影响“不要的段落之间添加空间的最小版本相同的风格“:

Sub AddSpaceBetweenParagraphsOfSameStyle() 
' 
' AddSpaceBetweenParagraphsOfSameStyle Macro 
' Add space between paragraphs of the same style. 
' 
End Sub 

Sub RemoveSpaceBetweenParagraphsOfSameStyle() 
' 
' RemoveSpaceBetweenParagraphsOfSameStyle Macro 
' Remove space between paragraphs of the same style. 
' 
End Sub 

我看着the documentation for ParagraphFormat和搜索相关的属性,但没有发现任何作品。如何以编程方式更改“不要在相同样式的段落之间添加空格”?

+0

如果您发布您尝试的代码,我们可以帮助您更好地完成任务。 – RubberDuck

+0

您可以通过阅读我的文章并使用宏记录器来生成我尝试过的代码,如前所述。 。 。但正如我所描述的那样,记录的代码遗漏了我想要做的事情,所以发布它将无济于事。 – Homer

+0

嘿,我只是想帮你找到答案。 SO不是你的私人服务台。如果您提供[最小,完整和可验证示例](http://stackoverflow.com/help/mcve),则您更有可能收到及时,准确的答案。这表明你已经付出了努力。社区成员更可能帮助表现出努力的人。 – RubberDuck

回答

4

此属性与样式相关,而不与段落(其中建议您设置此属性的窗口标题)。这是你看看下面的代码:

ActiveDocument.Styles("Normal").NoSpaceBetweenParagraphsOfSameStyle = False 
ActiveDocument.Styles("Normal").NoSpaceBetweenParagraphsOfSameStyle = True 
+0

我应该提到我想处理当前的选择。理想情况下,我会坚持一小组样式(标题,正常,列表段落),并始终如一地应用它们,但我需要处理凌乱,特殊的样式。要在不修改内置样式(或创建新样式)的情况下更改段落格式,可以使用Selection.Style或回退到内置对话框。 – Homer

4

宏录制认识不断变化的间距,而不是“不一样风格的段落之间添加空间”(页面布局>段落)。要更改段落格式,而无需修改内置样式(或创建新的风格),我可以使用Selection.Style:

Selection.Style.NoSpaceBetweenParagraphsOfSameStyle = False 

或退回到内置对话框:

With Dialogs(wdDialogFormatParagraph) 
    .Before = 12 
    .After = 12 
    .NoSpaceBetweenParagraphsOfSameStyle = False 
    .Execute 
End With 
+0

在Word 2013中,只有当我将该值设置为“False”时,这才适用于我。试图将其设置为“True”不起作用。任何其他提示? –

0
winword.ActiveDocument.Styles["Normal"].NoSpaceBetweenParagraphsOfSameStyle = true; 
winword.ActiveDocument.Styles["List Paragraph"].NoSpaceBetweenParagraphsOfSameStyle = false; 

在单词doc上按Alt + Ctl + Shift + S查看所有样式

相关问题