WD: Inserting Macro Variable Contents into a Document Window

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

   ARTICLE-ID: Q161407
   TITLE     : 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
winword macword
Keywords : kbmacroexample macword ntword winword word7 word8 word95 word97 macword98 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,97; MACINTOSH:6.0,6.0.1
Platform : MACINTOSH Win95 WINDOWS
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.