我正在VBA中为MS Word编制一个宏观方案,以复制突出术语,并将其贴在另一份文件中。 问题是,我不能在文件结尾处停下来,它从文件一开始就继续搜寻,从来不停。
谁能帮助我?
这里是宏观法典:
Sub gethigh()
gethigh Macro
MsgBox ("Before processing the file, this macro is going to save it as: << sourcedoc.doc >> and to create another document called: << targetdoc.doc >> and will then perform the export. Click OK to continue.")
ActiveDocument.SaveAs ("sourcedoc.doc")
Documents.Add
ActiveDocument.SaveAs "targetdoc.doc"
Documents("sourcedoc.doc").Activate
Selection.GoTo What:=wdGoToLine, Which:=wdGoToFirst
Selection.Find.ClearFormatting
Do
Selection.Find.Highlight = True
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
End With
Selection.Find.Execute
Selection.Copy
Documents("targetdoc.doc").Activate
Selection.GoTo What:=wdGoToLine, Which:=wdGoToLast
Selection.PasteAndFormat wdPasteDefault
Selection.Find.ClearFormatting
Selection.InsertBreak Type:=wdLineBreak
Documents("sourcedoc.doc").Activate
Loop
Documents("targetdoc.doc").Activate
Selection.Find.ClearFormatting
Selection.Find.Highlight = True
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Highlight = False
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Documents.Save noprompt:=True
MsgBox "Processing is complete."
End Sub