WD: Inserting Macro Variable Contents into a Document Window

ID: Q86079


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 95, versions 7.0, 7.0a
  • Microsoft Word for the Macintosh, versions 6.0, 6.0.1


SUMMARY

This article includes macro examples for inserting text into a Microsoft Word for Windows document using WordBasic commands.


MORE INFORMATION

The following example WordBasic macro can be used to insert the contents of the Name$ variable at the insertion position in the active document window:


   Sub MAIN
      ' A name is assigned to Name$ variable
      Name$ = "John Doe"
      ' Contents of Name$ variable inserted into document.
      Insert Name$
   End Sub 
The following sample macro can be used to insert the contents of the Name$ variable as literal text, using the QUOTE field:

   Sub MAIN
      ' A name is assigned to Name$ variable
      Name$ = "John Doe"
      InsertField "quote " + Chr$(34) + Name$ + Chr$(34)
   End Sub 
The above macro produces the following field syntax:
{quote "John Doe"}

Field result = John Doe
The result of a QUOTE field is the text typed between the quotation marks. The Chr$(34) command above is the quotation mark character (").

NOTE: Microsoft provides macros "as is" without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

For information about how to do this in Word 97 and later, please see the following articles in the Microsoft Knowledge Base:
Q161407 WD97: VB Macro Examples to Insert Text into a Document


REFERENCES

"Using WordBasic," by WexTech Systems and Microsoft, pages 236, 239

Additional query words: winword2 insert text word6 word7 winword word95 macword

Keywords : kbmacro kbmacroexample macword98 winword ntword macword word7 word95
Version : MACINTOSH:6.0,6.0.1; 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
Platform : MACINTOSH WINDOWS
Issue type : kbhowto


Last Reviewed: October 13, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.