需要脚本忽略MSword表 - 可能是语法的一个简单问题

时间:2014-05-13 13:53:14

标签: vba ms-word office-2007

我的代码处理表有问题,特别是我希望代码忽略它们。我不希望这个代码适用于表格,所以我认为我会使用“Selection.Information(wdWithInTable)= False”来清除这些内容。不幸的是我不知道如何选择脚本当前正在工作的段落。

我尝试将Selection.Paragraphs(i).Range.Select放入****,但这并没有消除使用表格的第一行,我不知道为什么。我是VBA和语法的新手,所以我假设这是问题。

Dim prePara As Paragraph
Dim curPara As Paragraph
Dim nextPara As Paragraph

For i = 2 To ActiveDocument.Paragraphs.Count

    Set prePara = ActiveDocument.Paragraphs(i - 1)
    Set curPara = ActiveDocument.Paragraphs(i)


    If curPara.LeftIndent <= prePara.LeftIndent And curPara.Style = "Normal" Or curPara.Style = "List Paragraph" Then

        ***** 'here is where I tried Selection.Paragraphs(n).Range.Select but it didn't work
        If Selection.Information(wdWithInTable) = False Then
            If curPara.LeftIndent < prePara.LeftIndent Then
                curPara.LeftIndent = prePara.LeftIndent
            End If
        End If
    End If
Next

1 个答案:

答案 0 :(得分:1)

这句话:

Selection.Paragraphs(i).Range.Select

您正在尝试选择一个选择对象。

尝试:

ActiveDocument.Paragraphs(i).Range.Select