测试,首行缩进2个字符,代码为:
Sub 宏2()
'
' 宏2 宏
'
'
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(0)
.RightIndent = CentimetersToPoints(0)
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
.LineSpacingRule = wdLineSpaceSingle
.Alignment = wdAlignParagraphJustify
.WidowControl = False
.KeepWithNext = False
.KeepTogether = False
.PageBreakBefore = False
.NoLineNumber = False
.Hyphenation = True
.FirstLineIndent = CentimetersToPoints(0.35)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 2
.LineUnitBefore = 0
.LineUnitAfter = 0
.MirrorIndents = False
.TextboxTightWrap = wdTightNone
.AutoAdjustRightIndent = True
.DisableLineHeightGrid = False
.FarEastLineBreakControl = True
.WordWrap = True
.HangingPunctuation = True
.HalfWidthPunctuationOnTopOfLine = False
.AddSpaceBetweenFarEastAndAlpha = True
.AddSpaceBetweenFarEastAndDigit = True
.BaseLineAlignment = wdBaselineAlignAuto
End With
End Sub
主要代码貌似是.FirstLineIndent = CentimetersToPoints(0.35),由厘米转为磅,网上介绍和字符的字号有关,但更改字号大小后,录制的缩进2个字符仍然是 以上代码。运行后没有问题。
测试将代码如果只保留.FirstLineIndent = CentimetersToPoints(0.35),删掉其他语句,实际效果就不是想要的结果(字号大时,缩进没有达到2个字符)。
检查发现,以上代码可以简化为:——测试正常
Sub 宏3()
'
' 宏3 宏
'
'
With Selection.ParagraphFormat
.CharacterUnitFirstLineIndent = 2
End With
End Sub
追问我也曾测试用精简后代码反复测试,但实际效果不理想。
使用场景如下:
别人给我发一份稿,我需要在审核后,添加固定内容的附件并打印;
重点就在添加的附件那里。
“附件1”字样,是不需要缩进的,而附件的正文,是首行缩进2字符;
附件2同1。
问题来了,录制的时候,一切操作都有正常反馈,但在重新调用宏时候,无论是完整的还是精简的,只有第一次缩进会成功,而后的撤销缩进完全无效。所以这不是代码本身的问题。
追答那就是你使用的问题了 ,需要先选中要首行缩进的所有段落,再执行代码才行。