gpt4 book ai didi

vba - 以编程方式更改“不要在相同样式的段落之间添加空格”

转载 作者:行者123 更新时间:2023-12-04 16:34:17 25 4
gpt4 key购买 nike

我正在尝试以编程方式更改“不要在相同样式的段落之间添加空格”。为了解决该问题,我记录了一个宏,在该宏中,我打开了“段落”对话框(“页面布局”>“段落”),选中了该复选框(不添加空间),并在一个宏中取消了该复选框(添加空间)。都不会影响“不要在相同样式的段落之间添加空格”。 。 。并且它们具有相同的代码:

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并搜索了一个相关属性,但没有发现任何有效的方法。如何以编程方式更改“不要在相同样式的段落之间添加空格”?

最佳答案

此属性与“样式”相关,而不与“段落”相关(建议在窗口标题中设置此属性)。这是您要查找的代码:

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

关于vba - 以编程方式更改“不要在相同样式的段落之间添加空格”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23418243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com