Automating a Paste from Excel to Word for Windows

Last reviewed: November 4, 1994
Article ID: Q57637
The information in this article applies to:
  • Microsoft Excel for Windows, versions 2.1 and 3.0

SUMMARY

The information below describes a macro technique that makes it possible to automatically paste data from Microsoft Excel into Word for Windows.

MORE INFORMATION

The following points are assumed in the sample macro:

  1. The area to be copied in Microsoft Excel has been named "area1".

  2. The sheet containing "area1" is the active sheet.

  3. The name of the Word for Windows document is contained in cell B1 of the active sheet.

  4. There is enough system memory to load Word for Windows, and the paste area is legal within the Word document.

When executed, this macro copies the named range from Microsoft Excel, starts and loads the named document into Word for Windows, performs the paste at the current insertion point, saves the document, and quits Word.

The macro code is as follows:

   A1: title
   A2: =SELECT(!area1)
   A3: =COPY()
   A4: =EXEC("c:\winword\winword.exe "&!B1,3)
   A5: =SEND.KEYS("%ep%fx~")
   A6: =RETURN()


Cell B1 contains the path and filename of the Word for Windows document (for example, the text "C:\WINWORD\TEST.DOC").

The Microsoft Excel data is pasted into Word for Windows as a table.

For more information, query on the following words:

   SEND.KEYS and data and Excel and pasted and table


KBCategory: kbinterop
KBSubcategory:

Additional reference words: 2.1 2.10 2.1c 2.10c 2.10d 2.1d 3.0 3.00


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: November 4, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.