How to check if a Paragraph is in a Table or not in MS-Word macro?

后端 未结 3 968
忘了有多久
忘了有多久 2021-01-02 18:02

The paragraph object in the Word has a property called Range. Within this Range object has a property called Cells.

For paragraph that are not in a table, this prop

3条回答
  •  无人及你
    2021-01-02 18:38

    You can't call the Cells method unless the paragraph is in a table. You need to use a different method to determine whether the range is in a table.

    You can use either...

    paragraph.Range.Tables.Count > 0
    

    ...or...

    paragraph.Range.Information(wdWithinTable)
    

    Note that the second one looks more obvious, but is actually slower (only a problem if you're doing this inside a loop).

提交回复
热议问题