如何在MS-Word宏中检查段落是否在表格中? [英] How to check if a Paragraph is in a Table or not in MS-Word macro?

查看:256
本文介绍了如何在MS-Word宏中检查段落是否在表格中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Word中的段落对象具有一个称为Range的属性.在此Range对象中,有一个称为Cells的属性.

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

对于不在表中的段落,此属性Paragraph.Range.Cells设置为".这可以在调试"模式下的监视"窗口中看到.

For paragraph that are not in a table, this property Paragraph.Range.Cells is set to "". This can be seen in the Watches window in debug mode.

对于表中的段落,属性Paragraph.Range.Cells中具有其他属性,例如,它具有名为Count的属性.

For paragraph that are in a table, the property Paragraph.Range.Cells has other properties in it, for example it has a property called Count.

我正在使用Paragraph.Range.Cells的此属性来确定该段落是否在表中.但是,我似乎无法弄清楚如何对此进行测试.

I am using this property of Paragraph.Range.Cells to determine if the paragraph is in a table or not. However, I cant seem to figure out how to test this.

例如,我不能像这样简单地进行测试...

For example, I cannot simply test like this...

如果段落.范围.单元格<>为空则....甚至 如果是IsNull(paragraph.Range.Cells)然后...

If paragraph.Range.Cells <> Null Then.... or even If IsNull(paragraph.Range.Cells) Then ...

它抛出运行时错误'5907'此位置没有表

It throws a Run-time error '5907' There is no table at this location

那么,我将如何对此进行测试?谢谢

So, how would I test for this? thanks

推荐答案

您可以使用

You can use the Information property:

If Selection.Information(wdWithInTable) Then
  'What ever you'd like to do
End If

因此,您不需要任何手动错误捕获机制.

Hence you don't need any manual error catching mechanisms.

这篇关于如何在MS-Word宏中检查段落是否在表格中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆