Multiple Apps

Paste Data From Excel To Word

Ease of Use

Intermediate

Version tested with

2002 

Submitted by:

Jacob Hilderbrand

Description:

Take data from your excel spreadsheet and programatically paste it into a new Word document 

Discussion:

You have a bunch of data in Excel, but you want to put some of it into Word. Maybe you input a lot of data into Excel, but you have to make a weekly report with just some of the data and put it in Word. This code will paste the data in automatically and also give you an idea of how to control Word from Excel. 

Code:

instructions for use

			

Option Explicit Sub PasteToWord() Dim AppWord As Word.Application Set AppWord = CreateObject("Word.Application") AppWord.Visible = True ' Change the range to suit your needs. See the How to Use for this code Sheets("Sheet1").Range("A1:C10").Copy AppWord.Documents.Add AppWord.Selection.Paste Application.CutCopyMode = False Set AppWord = Nothing End Sub

How to use:

  1. Open Excel.
  2. Press Alt + F11 to open VBE.
  3. Insert | Module.
  4. Paste the code there.
  5. Tools | References - Check to make sure that "Microsoft Word 10.0" is checked; if not then add the reference (Note that the number 10.0 may be different based on your version of Excel).
  6. Change this line <<Sheets("Sheet1").Range("A1:C10").Copy>> to the sheet and range you would want to copy.
  7. Close VBE (Alt + Q or press the X in the top right corner).
  8. From the Tools menu select Macro | Macros
  9. Select "PasteToWord" and press Run
 

Test the code:

  1. Refer to the "How To Use" section
  2. Download the attachment for a working example
 

Sample File:

PasteToWord.ZIP 7.56KB 

Approved by mdmackillop


This entry has been viewed 265 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express