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

后端 未结 3 961
忘了有多久
忘了有多久 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:36

    *Edited (if Err=) changed to (If Err<>)

    You can simply allow the error to happen and catch it using OnError statement

    Dim ParagraphIsTable As Object
    
        OnError Resume Next        'allows errors to happen but execute next instruction
        ParagraphIsTable = paragraph.Range.Cells
    
      If Err <> 5907 Then '(this is to check for a specific error that might have happened)
              'No Error occured, this means that ParagraphIsTable variable must contain a value
              ' Do the rest of your code here
        Else
              ' an Error occured, this means that this is not a table
              ' do whatever
        End If
    OnError Goto 0          ' This cancels the effect of OnError Resume Next
                      ' Which means if new errors happen, you will be prompt about them
    

提交回复
热议问题