Word删除空白行

时间:2014-01-30 15:59:25

标签: vbscript ms-word

我想清理一个自动生成的Word文档。

本文档包含多个表格,每个表格之间有许多空白行。我想开发一个只在每个表之间保留一个空行的宏。

我不知道是否可以做到。现在我坚持:

Dim i As Integer
Dim tTable As Table
For i = 0 To ActiveDocument.Tables.Count
    Set tTable = ActiveDocument.Tables.Item(i)

    ' ???

Next

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我发现了如何做到这一点:

Dim ParagraphToTrim As Range
Dim tTable As Table
Dim aTables() As Table

Set aTables = ActiveDocument.Tables

For Each tTable In aTables
    ' Supply a Start and End value for the Range.
    Set ParagraphToTrim = ActiveDocument.Range(tTable.Range.Next(Unit:=wdParagraph).Start, tTable.Range.Next(Unit:=wdTable).Start)
    ' Keep at least a paragraph between each table
    If ParagraphToTrim.Paragraphs.Count > 1 Then
        With ParagraphToTrim
            ' Change the start of the range
            .MoveStart Unit:=wdParagraph
            .Delete
        End With
    End If
Next
相关问题