我正在尝试编写一个 vba word 宏来搜索所有打开的文档,找到所有出现的文本“DocumentEnd9999”,并删除每个文档中该文本下方的所有内容。
Sub deletion()
Dim endTerm As String
endTerm = "DocumentEnd9999"
'Loop Dim
Dim n, c As Integer
n = Application.Documents.Count
For c = 1 To n
Set myRange = Application.Documents(c).StoryRanges
For Each myRange In ActiveDocument.StoryRanges
Selection.Find.ClearFormatting
With Selection.Find
.Text = endTerm
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute
Selection.Extend
Selection.Find.ClearFormatting
With myRange.Find
myRange.Characters.Last.Select
.Forward = True
.Wrap = wdFindAsk
End With
Application.DisplayAlerts = False
Selection.Find.Execute
Selection.Delete
Next myRange
Next c
End Sub