不好意思,最近太忙。
思路:将需要删除的文本录入另一文档(示例中为"tmep.doc")的表格中,通过代码循环表格的单元格,并取得文本,再回到该文档(楼主文档为“smaple1.doc")中,进行替换为“”的操作。其目的是增强可控性,和一次性删除操作。
Sub deltextintables()
Dim i, deltext
On Error Resume Next
Application.ScreenUpdating = False
For Each i In Documents("temp").Tables(1).Range.Cells
i.Select
deltext = ActiveDocument.Range(Start:=Selection.Range.Start, End:=Selection.Range.End - 1)
Documents("sample1").Activate
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = deltext
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next i
Application.ScreenUpdating = True
End Sub
[此贴子已经被作者于2004-1-6 17:24:59编辑过] |