我有一个包含多个表的文档,我需要在第一列的每个单元格中查找 并执行下一个替换:
是否可以选择要查找的列,以便将其用于其他文档,替换?
答案 0 :(得分:0)
你走了:
Sub Replace_in_Tables(strFind As String, strReplace As String, intColumn As Integer)
Dim oTable As Table
Dim oRow As Row
For Each oTable In ThisDocument.Tables
For Each oRow In oTable.Rows
oTable.Cell(oRow.Index, intColumn).Range.Text = Replace(oTable.Cell(oRow.Index, intColumn).Range.Text, strFind, strReplace)
Next oRow
Next oTable
End Sub
这样称呼:
Sub test()
' replace in all tables of this document, on column 1, the string "aaa" with "xxxxxxxxxxx"
Replace_in_Tables "aaa", "xxxxxxxxxxxxx", 1
End Sub
这将仅替换字符串...不确定您的查找/替换示例是否是正则表达式,因为在您的问题中没有明确说明。