Microsoft KB Archive/86079

{|
 * width="100%"|

WD: Inserting Macro Variable Contents into a Document Window

 * }

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$ = &quot;John Doe&quot; ' 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$ = &quot;John Doe&quot; InsertField &quot;quote &quot; + Chr$(34) + Name$ + Chr$(34) End Sub The above macro produces the following field syntax:

{quote &quot;John Doe&quot;}

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 (&quot;).

NOTE: Microsoft provides macros &quot;as is&quot; 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"