我有一个导出的Word文档,其中由数据库提取器构造的表格在单元格中包装的行之间有空格,我可以通过选择表格并使用段落对话框,但有很多表,我想自动执行此操作。我想为Word 2007文档中的所有表格设置空格间隔
在选择文档中的所有表格后(我可以用VBA做到的),我必须要做的事情是设置添加空间前和添加空间在= 0之后,我认为它也暗中设置了AddSpaceBeforeAuto = AddSpaceAfterAuto = False
。
于是我开始用一个简单的选择子程序:
Sub selecttables()
Dim mytable As Table
Application.ScreenUpdating = False
For Each mytable In ActiveDocument.Tables
mytable.Range.Editors.Add wdEditorEveryone
Next
ActiveDocument.SelectAllEditableRanges (wdEditorEveryone)
ActiveDocument.DeleteAllEditableRanges (wdEditorEveryone)
Application.ScreenUpdating = True
End Sub
这工作得很好,叶选择了所有我的表。我现在要做的就是设置相应的ParagraphFormat成员,以将段落对话框中这些属性的设置模拟为零和false。
我尝试了三种方法: 1.全局配置值Normal样式(其中所有的表使用) 2.如它们被总选择所选 3.设置值设置为每个表中的值,在所有表被选中之后。执行
当我这样做selecttables()
后手动,我做的方法3.
下面实际上是尝试所有这三种方法的功能。我有选择性地评论他们,发现没有任何一种方法可行,三者都不起作用。
对于方法3,我尝试了“With Selection.Range.Style.ParagraphFormat”和“With Selection.Range.ParagraphFormat”,但都没有成功。
我也想设置表属性,“允许行打破页面”为False(因为,严重的是,True的默认值真的是愚蠢的!),并不能指出如何做到这一点。
下面是函数:
Sub FixTables()
Dim mytable As Table
Dim i As Integer
Application.ScreenUpdating = False
' METHOD 1:
ActiveDocument.Styles("Normal").ParagraphFormat.Space1
ActiveDocument.Styles("Normal").ParagraphFormat.SpaceAfter = 0
ActiveDocument.Styles("Normal").ParagraphFormat.SpaceBefore = 0
ActiveDocument.Styles("Normal").ParagraphFormat.SpaceAfterAuto = False
ActiveDocument.Styles("Normal").ParagraphFormat.SpaceBeforeAuto = False
For Each mytable In ActiveDocument.Tables
' METHOD 2:
With mytable.Style.ParagraphFormat
.Space1
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
End With
mytable.Range.Editors.Add wdEditorEveryone
Next
ActiveDocument.SelectAllEditableRanges (wdEditorEveryone)
ActiveDocument.DeleteAllEditableRanges (wdEditorEveryone)
'
With Selection.Style.ParagraphFormat
.SpaceBefore = 0
.SpaceBeforeAuto = False
.SpaceAfter = 0
.SpaceAfterAuto = False
End With
Application.ScreenUpdating = True
End Sub