Microsoft Office Tutorials and References
In Depth Information
Copying an Excel Range to a Word Document
copying An ExcEl rAngE To A Word docuMEnT
Suppose you have a table of data in your Excel workbook on Sheet1 in range A1:H25. You want to
export the table into an existing Word document named myWordDoc.docx , which you know exists
and you know is closed. To make it interesting, say the task calls for the following set of actions:
Open Word.
Open myWordDoc.docx .
Export the data table from Excel into the myWordDoc.docx document.
Save myWordDoc.docx .
Close myWordDoc.docx .
The following macro accomplishes this task very quickly. Note that you can copy a worksheet’s
used range or current region of a cell; you do not need to refer to a specific range address as this
example does.
Sub ExportFromExcelToWord()
‘Turn off ScreenUpdating
Application.ScreenUpdating = False
‘Copy the Excel range to be exported.
‘Declare object variables.
Dim WdApp As Object, wddoc As Object
‘Open Word
Set WdApp = CreateObject(“Word.Application”)
‘Open the Word document that will accept the exported data.
Set wddoc = WdApp.Documents.Open(Filename:=”C:\Your\File\Path\myWordDoc.docx”)
‘Paste the copied date from Excel to the Word document.
‘Close the Word document and save changes
wddoc.Close savechanges:=True
‘Quit the Word application.
‘Set the Object variables to Nothing to release system memory.
Set wddoc = Nothing
Set WdApp = Nothing
‘Exit Copy mode
Application.CutCopyMode = False
‘Turn ScreenUpdating back on.
Application.ScreenUpdating = True
End Sub
prinTing A Word docuMEnT froM ExcEl
To print a Word document, you can use the PrintOut method to print the entire document, or only
a portion of the document if you so choose. The following macro shows an example of opening and
printing a Word document:
Sub PrintWordDoc()
‘Declare object variables.
Search JabSto ::

Custom Search