在word中可以设置段落的行距为单倍行距、双倍行距、固定行距等。
当对所有的段落都设置行距时,word文档中的表格中的行距也会相应的一起变化。如果文档中还含有嵌入式图片,嵌入式图片所在的段落的行距也会一起变化。
如下所示为尚未设置段落行距为固定值之前:

当设置段落行距为固定值28磅后,会变成如下图所示:

对比上下两张图可以看出,表格内的行距也变化了,图片被遮住了。
为此,可以用如下的vba代码来设置段落的行距,同时排除表格和嵌入式图片:
Sub QQ1722187970()
Dim oILS As InlineShape
Dim oP As Paragraph
Dim oDoc As Document
Set oDoc = Word.ActiveDocument
With oDoc
With .Paragraphs
.LineSpacingRule = wdLineSpaceAtLeast
End With
For Each oP In .Paragraphs
With oP
'排除表格
If .Range.Information(wdWithInTable) = False Then
.LineSpacingRule = wdLineSpaceExactly
.LineSpacing = 28
End If
End With
Next
'排除嵌入式图片
For Each oILS In .InlineShapes
With oILS
.Range.ParagraphFormat.LineSpacingRule = wdLineSpaceAtLeast
End With
Next
End With
End Sub


发表评论