VBA代码如下:
Sub set_write_simple()
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(0)
.RightIndent = CentimetersToPoints(0)
.FirstLineIndent = CentimetersToPoints(0)
.OutlineLevel = wdOutlineLevel1
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
End With
Selection.TypeText Text:="一级" '这句话没有缩进,正常
Selection.TypeParagraph
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(1.06)
.RightIndent = CentimetersToPoints(0)
.FirstLineIndent = CentimetersToPoints(0.35)
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 6
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 2
End With
Selection.TypeText Text:="正文" '这句话做了段落缩进和首行缩进,正常
Selection.TypeParagraph
With Selection.ParagraphFormat
.LeftIndent = CentimetersToPoints(0)
.RightIndent = CentimetersToPoints(0)
.FirstLineIndent = CentimetersToPoints(0)
.OutlineLevel = wdOutlineLevel1
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
End With
Selection.TypeText Text:="一级" '这句话显示异常,本没有任何缩进却缩进了。
End Sub
在word中用VBA做段落缩进正常,但取消缩进时发现取消不了。 录制时正常,但是重复运行时发现无法取消缩进
答案:2 悬赏:20 手机版
解决时间 2021-02-10 20:35
- 提问者网友:嗝是迷路的屁
- 2021-02-10 15:23
最佳答案
- 五星知识达人网友:天凉才是好个秋
- 2021-02-10 16:46
请在每一行 With Selection.ParagraphFormat 的后面添加以下一行:
.Reset
将所有的段落格式清除,然后用后续的代码重新设置即可。
以下是完整的、精简后的代码:
Sub set_write_simple()
With Selection.ParagraphFormat
.Reset
.OutlineLevel = wdOutlineLevel1
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
End With
Selection.TypeText Text:="一级" '这句话没有缩进,正常
Selection.TypeParagraph
With Selection.ParagraphFormat
.Reset
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 6
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 2
End With
Selection.TypeText Text:="正文" '这句话做了段落缩进和首行缩进,正常
Selection.TypeParagraph
With Selection.ParagraphFormat
.Reset
.OutlineLevel = wdOutlineLevel1
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
End With
Selection.TypeText Text:="一级" '这句话显示异常,本没有任何缩进却缩进了。
End Sub
.Reset
将所有的段落格式清除,然后用后续的代码重新设置即可。
以下是完整的、精简后的代码:
Sub set_write_simple()
With Selection.ParagraphFormat
.Reset
.OutlineLevel = wdOutlineLevel1
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
End With
Selection.TypeText Text:="一级" '这句话没有缩进,正常
Selection.TypeParagraph
With Selection.ParagraphFormat
.Reset
.OutlineLevel = wdOutlineLevelBodyText
.CharacterUnitLeftIndent = 6
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 2
End With
Selection.TypeText Text:="正文" '这句话做了段落缩进和首行缩进,正常
Selection.TypeParagraph
With Selection.ParagraphFormat
.Reset
.OutlineLevel = wdOutlineLevel1
.CharacterUnitLeftIndent = 0
.CharacterUnitRightIndent = 0
.CharacterUnitFirstLineIndent = 0
End With
Selection.TypeText Text:="一级" '这句话显示异常,本没有任何缩进却缩进了。
End Sub
全部回答
- 1楼网友:慢性怪人
- 2021-02-10 17:46
with selection.paragraphformat
.leftindent = centimeterstopoints(0) '左缩进为0
.firstlineindent = centimeterstopoints(0) '首行缩进为0
end with
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯