WD: Macros to Determine If Line or Document Is Empty

ID: Q97435

The information in this article applies to:

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          : wordnt kbmacroexample winword ntword macword word6 winword2 word7 word95 macword6 
Version           : WINDOWS:2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a; winnt:6.0
Platform          : WINDOWS winnt
Issue type        : kbhowto

Last Reviewed: February 7, 1999