EditFind and EditSearch Not Working As Expected

Last reviewed: July 30, 1997
Article ID: Q98874
The information in this article applies to:
  • Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, version 7.0

SUMMARY

If a search direction is not specified with the Microsoft WordBasic EditSearch or EditFind statements, the search routine may exhibit erratic behavior. The search statement may find the next instance of a search string, the previous instance, or nothing at all. This behavior occurs because the search function of Word for Windows remembers the last direction and uses this as the default for the next search.

MORE INFORMATION

The following WordBasic statements behave differently depending on the current search direction and the position of the insertion point.

Word for Windows 2.x and later

EditFind .Find = "Word"

Word for Windows 1.x

EditSearch .Search = "Word"

Values for the .Direction Parameter

   Value     Direction of Search
   -----------------------------

   0 (zero)  Searches toward the end of the document.
   1         Searches toward the beginning of the document.

The default is the direction used in the previous search or 0 (zero) the first time the Find or Replace command is run.

Word for Windows 2.x and later

   Value     Direction of Search
   -----------------------------

   0 (zero)  Searches backwards toward beginning of document, without
             prompt
   1         Searches forward toward end of document, with prompt
   2         Searches forward toward end of document, without prompt

To force a consistent search, always specify the direction to search. For example, the following macro will always search upwards towards the beginning of the document from the insertion point:

Sub Main
EditFind .Find = "Word", .Direction = 0
End Sub

To search the entire document, move the insertion point to the beginning of the document and set the direction parameter to 2 (search forward without prompt).

Sub Main
StartOfDocument EditFind .Find = "Word", .Direction = 2
End Sub

REFERENCES

"Using WordBasic" by WexTech Systems, Inc. and Microsoft Corporation, page 180.

Kbcategory: kbusage kbmacro KBSubcategory:


Additional query words: winword2 1.0 1.10 1.10a 2.0 2.0a 2.0a-CD
winword 7.0 word95 word7 word6 2.0b 2.0c editfind editsearch text found
direction find
Version : 1.x 2.x 6.0 6.0a 6.0c 7.0
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.