WD: Macros to Test for an Existing AutoText Entry Name

Last reviewed: February 2, 1998
Article ID: Q86441
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 NT, version 6.0
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Word for the Macintosh, versions 6.0, 6.0.1

SUMMARY

When you write macros in Microsoft Word for Windows, it may be necessary to test for the existence of an AutoText ("glossary" prior to Word 6.0) entry before inserting the contents of the entry. If your macro does not check for the existence of an AutoText entry before attempting to insert the contents into the document, you may receive one of the following error messages:

Word 6.x, 7.x

   The name you typed is not a valid AuotText entry. Use the AutoText
   button on the Standard toolbar to define AutoText entries that can be
   inserted as a long piece of text or a graphic.

Word 1.x, 2.x

   This glossary entry does not exist.


MORE INFORMATION

The following WordBasic macros test for an existing AutoText (glossary) entry.

Word 6.x, 7.x

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.

If the "test" AutoText entry resides in the Normal template, the following macro inserts the contents of the AutoText entry at the insertion position in the document. If the "test" entry does not exist in the Normal template, this macro example posts a message indicating that it does not exist.

   Sub Main
      'Assign AutoText name to string
      AutoTextName$ = "test"
      'AutoText exists?
      If GetAutoText$(AutoTextName$) = "" Then
         MsgBox "AutoText Name, " + AutoTextName$ + ", Does Not Exist"
      Else
         EditAutoText .Name = AutoTextName$
      End If
   End Sub

Word 2.x

If the "test" Glossary entry resides in the Normal template, the following macro inserts the contents of the Glossary entry at the insertion position in the document. If the "test" entry does not exist in the Normal template, this macro example posts a message indicating that it does not exist.

   Sub Main
      'Assign glossary name to string
      GlosName$ = "test"
      'Glossary exists?
      If GetGlossary$(GlosName$) = "" Then
         MsgBox "Glossary Name " + GlosName$ + " Does Not Exist "
      Else
         EditGlossary .Name = GlosName$
      End If
   End Sub

The following WordBasic macro tests for an existing glossary entry named "test" in the active template (template other than Normal):

   Sub Main
      GlosName$ = "test"
      If GetGlossary$(GlosName$, 1) = "" Then
         MsgBox "Glossary Name " + GlosName$ + " Does Not Exist "
      Else
         EditGlossary .Name = GlosName$, .Context = 1
      End If
   End Sub

The context of the GetGlossary and EditGlossary commands above is set to template instead of global.

These commands operate the same if the word Glossary is replaced by the word AutoText when Word 6.0 is used.

REFERENCES

"Using WordBasic," by WexTech Systems and Microsoft, pages 183 and 228


Additional query words: winword2 winword word95 word6 GetGlossary Insert
Glossary AutoText GetAutoText macword word7 winword
Keywords : kbmacroexample kbmacro
Version : WINDOWS:1.0,1.1,1.1a,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.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 2, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.