作为练习,试写了一小部分,是以当前光标所在单元格的字符为查找对象,然后按规则删除第2个表格中相应的字符。测试了若干次,不知是否还有错漏。另,运行时间有时达3秒,太长了,估计方法全不对头。不知在word中完成最快要多长时间 Sub shudu() ' Dim myrnum As Integer, mycnum As Integer, findtext As String Dim i As Integer, n As Integer, myceltext As String Dim st_time As Single, en_time As Single Application.ScreenUpdating = False 'st_time = Timer If Selection.Information(wdWithInTable) = True Then myrnum = Selection.Range.Information(wdEndOfRangeRowNumber) mycnum = Selection.Range.Information(wdEndOfRangeColumnNumber) findtext = Mid(ThisDocument.Tables(1).Cell(myrnum, mycnum).Range.Text, _ 1, Len(ThisDocument.Tables(1).Cell(myrnum, mycnum).Range.Text) - 2) With ThisDocument.Range.Tables(2) For i = 1 To 16 myceltext = Mid(.Rows(myrnum).Cells(i).Range.Text, _ 1, Len(.Rows(myrnum).Cells(i).Range.Text) - 2) .Rows(myrnum).Cells(i).Range.Text = _ Mid(Replace(myceltext, findtext, ""), 1) myceltext = Mid(.Rows(i).Cells(mycnum).Range.Text, _ 1, Len(.Rows(i).Cells(mycnum).Range.Text) - 2) .Rows(i).Cells(mycnum).Range.Text = _ Mid(Replace(myceltext, findtext, ""), 1) Next For i = 1 To 4 For n = 1 To 4 If InStr(.Rows(Int((myrnum - 1) / 4) * 4 + i).Cells _ (Int((mycnum - 1) / 4) * 4 + n).Range.Text, findtext) <> 0 Then myceltext = Mid(.Rows(Int((myrnum - 1) / 4) * 4 + i).Cells _ (Int((mycnum - 1) / 4) * 4 + n).Range.Text, 1, _ Len(.Rows(Int((myrnum - 1) / 4) * 4 + i).Cells _ (Int((mycnum - 1) / 4) * 4 + n).Range.Text) - 2) .Rows(Int((myrnum - 1) / 4) * 4 + i).Cells(Int((mycnum - 1) / 4) _ * 4 + n).Range.Text = Mid(Replace(myceltext, findtext, ""), 1) End If Next n Next i End With End If 'en_time = Timer 'Debug.Print en_time - st_time Application.ScreenUpdating = True End Sub |