WD: WordBasic Macros to Test for Annotations and Footnotes

Last reviewed: February 2, 1998
Article ID: Q89653
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

SYMPTOMS

In Microsoft Word, the ViewFootnotes and ViewAnnotations macro commands will return the following error messages if there are no annotations or footnotes in the active document:

   Word found no footnotes
   Word found no annotations

To avoid the above error messages you can test for the presence of footnotes or annotations in a document before using the ViewFootnotes or ViewAnnotations commands.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

The following Word macro will test for the presence of automatic footnotes in your document:

Note: This macro will not work with Word version 6.0 for the Macintosh. The CommandValid()function does not work with the ViewFootnotes command. The macro does work with Word version 6.0.1 for the Macintosh.

   Sub MAIN
      n = CommandValid("ViewFootnotes")
      If n <> - 1 Then
         MsgBox "There are no footnotes in this document."
      Else
         StartOfDocument
         EditFind .Find = "^f", .Direction = 0
         If EditFindFound() Then
            MsgBox "There are footnotes in this document"
         Else
            MsgBox "There are no footnotes in this document."
         End If
      End If
   End Sub

If you are using Word version 2.x for Windows, change the EditFind statement in the above macro to the following:

   EditFind .Find = "^2", .Direction = 2

The following Word macro will test for the presence of annotations in your document:

   Sub MAIN
      n = CommandValid("ViewAnnotations")
      If n <> - 1 Then
         MsgBox "There are no annotations in this document."
      Else
         StartOfDocument
         EditFind .Find = "^a", .Direction = 0
         If EditFindFound() Then
            MsgBox "There are annotations in this document"
         Else
            MsgBox "There are no annotations in this document."
         End If
      End If
   End Sub

If you are using Word version 2.x for Windows, change the EditFind statement in the above macro to the following:

   EditFind .Find = "^5", .Direction = 2

MORE INFORMATION

Macro Notes

  • The CommandValid command returns -1 if the "ViewAnnotations" or "ViewFootnotes" commands are available. In addition to checking whether the appropriate View command is valid, the above macros use the EditFind command to search for footnotes or annotation reference marks.
  • The .Find argument in the EditFind command uses "^f" to find automatic footnote reference marks and "^a" to find annotation reference marks.
  • The EditFindFound function tests whether a footnote reference or annotation reference was found in the above macros. You can replace the MsgBox commands with the logical branches of your macro.

For information about how to do this in Word 97 for Windows or Word 98 Macintosh Edition, please see the following article(s) in the Microsoft Knowledge Base:

   ARTICLE-ID: Q158854
   TITLE     : WD97: Compile Error If VB Code Doesn't Find Comments

REFERENCES

"Using WordBasic," by WexTech Systems and Microsoft, page 325 and 327

"Microsoft Word for Windows User's Guide," version 2.0, pages 265-266


Additional query words: winword2 word95 word7 word6 errmsg err msg
viewannotations viewfootnotes macword winword
Keywords : kbmacroexample macword ntword winword word6 word7 word95 wordnt
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 kbinfo


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