0
我正试图删除一组在发现所选文本后立即发生的句子(可能是1个或更多)。我使用Selection.Find来查找文本,但是我无法找到允许我在选择之后删除的任何内容,而不是删除选择本身。在VBA中发现在Word2010中选择后删除的文本
下面是代码片段:
Selection.Find.ClearFormatting
With Selection.Find
.Text = req
.Replacement.Text = ""
.Forward = True
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
End With
'execute search
Selection.Find.Execute
If Selection.Find.Found Then
'Found the tag, check for a duplicate
Selection.Find.Execute
If Selection.Find.Found Then
'Found a duplicate
err = True
err_req = err_req & " " & req
Else
num_updated = num_updated + 1
'Update the requirements text
' TODO: Delete the current requirements text
Selection.InsertAfter req_text_list(index)
'Set the requirement style
Selection.GoTo what:=wdGoToBookmark, Name:="\Para"
Selection.Style = ActiveDocument.Styles(STYLE_NAME_RQMT)
Selection.Collapse Direction:=wdCollapseEnd
End If
End If
任何帮助将非常感激。谢谢:)
看看这篇文章:http://stackoverflow.com/questions/497624/find-a-string-in-a-document-and-delete-everything-after - 它找到一个字符串,然后删除它后面的所有内容。你没有提到你如何决定删除多少句子。 –