Home » excel » copy Excel sheet to Word

copy Excel sheet to Word

Posted by: admin April 23, 2020 Leave a comment

Questions:

I need to export the sheet ‘GreatIdea’ to a Word document. ‘GreatIdea’ is divided into pages and my columns are based on these pages.

A – C contain a table of contents, D – F contain chapter 1, …

Sub test()

' Open LOL.docx'
Dim appWD As Word.Application
Set appWD = New Word.Application
Dim docWD As Word.Document
Set docWD = appWD.Documents.Open("C:\Users\TOM\Desktop\LOL.docx")
docWD.Activate
Sheets("Sheet1").Select

' Copy from GreatIdea to LOL.docx'

Range("A1:K40").Copy
appWD.Selection.PasteSpecial

appWD.ActiveDocument.SaveAs Filename:=ThisWorkbook.Path & "/" & "OEF_OFFERTE"
appWD.ActiveDocument.Close
appWD.Quit
Set appWD = Nothing
Set docWD = Nothing

End Sub

This copies everything into Word, but doesn’t copy the column layout. Other solutions to copy everything are accepted too. I just need to make sure all the data from every column gets copied.

Mike’s answer edited:

 Range("A1:C40").Copy
 appWD.Selection.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=True
How to&Answers:

As you are in a WORD application (AppWD), there’s a better function:

expression.PasteExcelTable(LinkedToExcel, WordFormatting, RTF)

Try one of these

AppWD.Selection.PasteExcelTable False, True, True   ' aequivalent to PasteSpecial As RTF
AppWD.Selection.PasteExcelTable False, False, True  ' keeps Excel formats
AppWD.Selection.PasteExcelTable False, False, False ' aequivalent to PasteSpecial As HTML

Good luck – MikeD