【发布时间】:2015-07-27 15:12:24
【问题描述】:
我在创建 Microsoft-Word 宏时遇到问题。这是我正在处理的宏。它成功地选择了 word 文档中的每个单独的表。
Sub FindSpecificTables()
Selection.WholeStory
Dim iResponse As Integer
Dim tTable As Table
'If any tables exist, loop through each table in collection.
For Each tTable In ActiveDocument.Tables
tTable.Select
If response = vbNo Then Exit For 'User chose to leave search.
Next
MsgBox prompt:="Search Complete.", buttons:=vbInformation
End Sub
但是,如果表格包含指定的字符串,我只需要选择表格。这应该很简单,但我无法弄清楚。如何在表格中搜索特定字符串?
我尝试使用以下条件语句调整代码:If tTable.Cell(1, 1) = "Adjusted:" Then tTable.Select; 见下面的例子。
Sub FindSpecificTables()
Selection.WholeStory
Dim iResponse As Integer
Dim tTable As Table
'If any tables exist, loop through each table in collection.
For Each tTable In ActiveDocument.Tables
If tTable.Cell(1, 1) = "MySpecifiedString:" Then tTable.Select
If response = vbNo Then Exit For 'User chose to leave search.
Next
MsgBox prompt:="Search Complete.", buttons:=vbInformation
End Sub
很遗憾,这不起作用。我的语法错了吗?大家有什么建议或建议吗?
【问题讨论】: