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

查看:46
本文介绍了如何在 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 设置为".这可以在调试模式下的 Watches 窗口中看到.

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...

如果paragraph.Range.Cells <> Null 那么.... 甚至如果 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天全站免登陆