在编程调成段落格式的时候遇到缩进控制不好用,百度到的这篇文章很给力。对原作者表示感谢
经过详细测试是有一个命令在起作用。
他就是:“以用字符单位为测量单位”,起作用。
正确的代码是:
Sub有趣的段落设置()
With
Selection.ParagraphFormat
If Word.Options.UseCharacterUnit = False Then
‘判断是否是选中了“用字符单位为测量单位”(word2007的叫法,2003类似)
‘没有选中则下面的代码顺序可以任意变化
.LeftIndent = CentimetersToPoints(0)
.RightIndent = CentimetersToPoints(0)
.FirstLineIndent = CentimetersToPoints(0)
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
Else
‘如果选中则下面的代码顺序不能随意变
‘即中文的设置必须在前。
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LeftIndent = CentimetersToPoints(0)
.RightIndent = CentimetersToPoints(0)
.FirstLineIndent = CentimetersToPoints(0)
End If
End
With
End Sub
当然也可直接用(不用判断):
Sub有趣的段落设置简化版()
With
Selection.ParagraphFormat
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
.LeftIndent = CentimetersToPoints(0)
.RightIndent = CentimetersToPoints(0)
.FirstLineIndent = CentimetersToPoints(0)
End
With
End Sub
调用
ActiveDocument.Paragraphs(i).Range.Select
Call 有趣的段落设置
原文地址http://club.excelhome.net/viewthread.php?tid=200873&extra=&page=1
加载中,请稍候......