WD: Macros to Test for an Existing AutoText Entry NameLast reviewed: February 2, 1998Article ID: Q86441 |
The information in this article applies to:
SUMMARYWhen 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 INFORMATIONThe following WordBasic macros test for an existing AutoText (glossary) entry.
Word 6.x, 7.xWARNING: 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.xIf 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 SubThe 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 SubThe 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |