Microsoft KB Archive/97435

{|
 * width="100%"|

WD: Macros to Determine If Line or Document Is Empty

 * }

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, versions 7.0, 7.0a
 * Microsoft 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 &quot;\Line&quot; 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$(&quot;\Line&quot;)) <= 1 Then Print &quot;Blank Line&quot; End Sub The following macro commands use the EmptyBookmark statement to determine if the reserved &quot;\Doc&quot; bookmark contains text. If the bookmark is empty, there is no text in the document.

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

Word 2.x
  Sub MAIN 'Is the document line blank? If Len(GetBookmark$(&quot;\Line&quot;)) <= 2 Then Print &quot;Blank Line&quot; End Sub