PDA

View Full Version : Paste XLS-Sheet into A Word Document



JPDO
10-23-2004, 06:49 AM
Hello,
Could any one tell me how i can "paste" an xls-sheet into a Word document?
The result should have an Excel-like presentation.(table with rows & columns)
Not a non-formatted text.
I try to include the Excel-sheet like an object but i do not want that there is a constant link between the Word document and the xls-workbook.

These are my statements:
Application.Workbooks.Open "C:\atest\pusectpf.xls"
Application.Worksheets("Crit").Activate
Application.ActiveSheet.UsedRange.Select
Application.Selection.Copy
ActiveDocument.Paragraphs(ActiveDocument.Paragraphs.Count).Range.PasteSpeci al
_ DataType:=wdPasteOLEObject
Application.CutCopyMode = False
Application.Windows("Pusectpf.xls").Close SaveChanges:=False

Is this the right way Or not ? :dunno

Thanks in advance for any reply.

Jacob Hilderbrand
10-23-2004, 09:32 AM
Try this:

Option Explicit

Sub PasteToWord()

Dim AppWord As Object

Set AppWord = CreateObject("Word.Application")
AppWord.Visible = True

'Change the range to suit your needs.
Sheets("Sheet1").UsedRange.Copy
AppWord.Documents.Add
AppWord.Selection.Paste

Application.CutCopyMode = False

Set AppWord = Nothing

End Sub

JPDO
10-23-2004, 09:47 AM
Thanks for the reply.
I replaced ".range.PasteSpecial ..." by ".range.Paste"
It works, but i wonder what happens with references, formulas ...
Are they resolved or should it be better that i do a "CopyPasteValue" of the Excelrange to itself before i paste it in a Word document ?
Could some one advise me in this matter ?
Thanks for your reply.

Jacob Hilderbrand
10-23-2004, 10:13 AM
It should just be the values automatically.