WD: Macro to Select AutoText Entry for Envelope Mailing AddressLast reviewed: February 2, 1998Article ID: Q97909 |
The information in this article applies to:
SUMMARYThe following Microsoft Visual Basic for Applications and WordBasic macro examples allow you to select an AutoText (or glossary) entry for an envelope mailing address. The macro displays the names of all of the available AutoText entries, allowing you to select one for your envelope mailing address, and it then inserts the contents of that entry into the Create Envelope dialog box. Prior to running the following macro, create AutoText (or glossary) entries for the mailing addresses that you use most often.
Visual Basic for ApplicationsMicrosoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.
Sub GetAutoTextForEnvelope() Dim strATName As String Dim strATValue As String ' Display AutoText list. With Dialogs(wdDialogEditAutoText) .Display strATName = .Name End With ' Extract AutoText Value from selected entry. strATValue = ActiveDocument.AttachedTemplate. _ AutoTextEntries(strATName).Value ' Show Envelope dialog. With Dialogs(wdDialogToolsEnvelopesAndLabels) ' Set value for delivery address to selected AutoText ' entry's value. .AddrText = strATValue .Show End With End Sub WordBasicWARNING: 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. Word 6.x, Word 7.x:
Sub MAIN num = CountAutoTextEntries(0) Dim gloss$(num - 1) For x = 1 To num gloss$(x - 1) = AutoTextName$(x, 0) Next x Begin Dialog UserDialog 320, 144, "Microsoft Word" Text 21, 8, 191, 13, "Choose a Glossary Entry:" ListBox 16, 39, 160, 84, gloss$(), .ListBox1 OKButton 199, 45, 88, 21 CancelButton 198, 74, 88, 21 End Dialog Dim dlg1 As UserDialog n = Dialog(dlg1) choice = dlg1.listbox1 glosstext$ = GetAutoText$(gloss$(choice), 0) Dim dlg As ToolsCreateEnvelope GetCurValues dlg dlg.EnvAddress = glosstext$ n = Dialog(dlg) If n <> 0 Then ToolsCreateEnvelope dlg End SubWord 2.x:
Sub MAIN num = CountGlossaries(0) Dim gloss$(num - 1) For x = 1 To num gloss$(x - 1) = GlossaryName$(x, 0) Next x Begin Dialog UserDialog 320, 144, "Microsoft Word" Text 21, 8, 191, 13, "Choose a Glossary Entry:" ListBox 16, 39, 160, 84, gloss$(), .ListBox1 OKButton 199, 45, 88, 21 CancelButton 198, 74, 88, 21 End Dialog Dim dlg1 As UserDialog n = Dialog(dlg1) choice = dlg1.listbox1 glosstext$ = GetGlossary$(gloss$(choice), 0) Dim dlg As ToolsCreateEnvelope GetCurValues dlg dlg.EnvAddress = glosstext$ n = Dialog(dlg) If n <> 0 Then ToolsCreateEnvelope dlg End SubTo display and choose from AutoText (glossary) entries in the current template rather than global entries, change the context parameter for the following commands from 0 (zero) to 1:
CountAutoTextEntries (CountGlossaries) AutoTextName$ (GlossaryName$) GetAutoText$ (GetGlossary$)The correct command to use is listed in the "To this" column of the following table.
Version of Word Change this To this --------------------------------------------------------------------- 6.x, 7.x num = CountAutoTextEntries(0) num = CountAutoTextEntries(1) 2.x num = CountGlossaries(0) num = CountGlossaries(1) REFERENCES"Using WordBasic," by WexTech Systems and Microsoft, pages 168, 228, 229, and 306.
|
Additional query words: choice addressee word95 winword winword2 cd
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |