WD: Macros to Determine If Line or Document Is Empty

Last reviewed: February 17, 1998
Article ID: Q97435
The information in this article applies to:
  • Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows NT, version 6.0
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Word for the Macintosh, versions 6.0, 6.0.1, 6.0.1a

SUMMARY

When you write a Wordbasic macro, you may need to know whether or not the insertion point is positioned within an empty document or a blank document line. The sample macros in this article determine if the current line or document is empty and then display a message regarding the current status.

MORE INFORMATION

The following macro commands use the Len() function to determine the character length of the current document line. The contents of the current line is captured using the reserved "\Line" bookmark. If the line length is one character, the line is considered blank or empty. A paragraph return is character 13 and a new line character is character 11 in Word 6.x.

Word 6.x-7.x

   Sub MAIN
      'Is the document line blank?
      If Len(GetBookmark$("\Line")) <= 1 Then Print "Blank Line"
   End Sub

The following macro commands use the EmptyBookmark statement to determine if the reserved "\Doc" bookmark contains text. If the bookmark is empty, there is no text in the document.

   Sub MAIN
      'Is the document empty?
      If EmptyBookmark("\Doc") Then Print "Empty Document"
   End Sub

Word 2.x

   Sub MAIN
      'Is the document line blank?
      If Len(GetBookmark$("\Line")) <= 2 Then Print "Blank Line"
   End Sub

REFERENCES

"Using WordBasic" by WexTech Systems, Inc. and Microsoft Corporation, Microsoft Press, pages 88-90.


Additional query words: blank doc special bookmark Getbookmark
emptybookmark
Keywords : kbmacroexample macword ntword winword winword2 word6 word7 word95 wordnt macword6
Version : WINDOWS:2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a; MACINTOSH:6.0,6.0.1,6.0.6.0.1a
Platform : MACINTOSH Win95 WINDOWS winnt
Issue type : kbhowto


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: February 17, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.