请参考: '* +++++++++++++++++++++++++++++
'* Created By I Love You_Word!@ExcelHome 2005-9-23 5:07:25
'仅测试于System: Windows NT Word: 10.0 Language: 2052
'№ 00033^The Code CopyIn [ThisDocument-ThisDocument]^'
'* -----------------------------
Option Explicit
Sub Test()
Dim myString As String, myDoc As Document, i As Range, oCell As Cell
Dim PostionNumber As Integer, myRange As Range, Target As Range
On Error Resume Next '忽略错误
Application.ScreenUpdating = False '关闭屏幕更新
'隐藏方式打开指定的更正表文档
Set myDoc = Documents.Open(FileName:="C:\Documents and Settings\My Documents\temp\附件\更正表.Doc", Visible:=False)
With myDoc
'遍历更正表文档中的表格1中的第一列单元格
For Each oCell In .Tables(1).Columns(1).Cells
'取得自造字文本,注意,你的自造字必须为单字,并且不可能会产生词组
myString = myString & .Range(oCell.Range.Start, oCell.Range.End - 1)
Next
' Debug.Print myString
Set myRange = Me.Content '定义一个RANGE对象
GT: For Each i In myRange.Words '在本文档中遍历各个词
PostionNumber = VBA.InStr(myString, i) '是否存在自造字
If PostionNumber > 0 Then '如果是自造字,根据返回的值,获得相应行号单元格
Set Target = .Range(.Tables(1).Cell(PostionNumber, 2).Range.Start, .Tables(1).Cell(PostionNumber, 2).Range.End - 1)
Target.Copy '目标区域复制
i.PasteAndFormat (wdFormatOriginalFormatting) '在当前词位置粘贴/请检查工具/选项/编辑:键入内容替换所选内容前为勾选.
Set myRange = Me.Range(i.End, Me.Content.End) '重新定义一个RANGE对象
GoTo GT '转到GT行,重新开始新的循环
End If
Next
.Close False '关闭更正表文档
End With
Application.ScreenUpdating = True '恢复屏幕更新
End Sub
'----------------------
[此贴子已经被作者于2005-9-23 5:06:27编辑过] |