English 中文(简体)
停止在文件结尾处居住
原标题:Stop looping at the end of a document

我正在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
问题回答

这里的问题是:

.Wrap = wdFindContinue

这说明它从一开始就要继续。





相关问题
Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Outlook 2007 CommandBarControl.Execute won t work

I recently switched to Outlook 2007 and noticed that my VBA-macros won t work. I use the following code to open a new appointment-item (and fill it automatically). It worked perfect in Outlook 2003, ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签