copy Excel sheet to Word

13,350

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

Share:
13,350
CustomX
Author by

CustomX

I'm a Network Engineer ready to help with a decent knowledge of Excel (VBA). I also enjoy gaming and a bit of web development. SOreadytohelp

Updated on June 04, 2022

Comments

  • CustomX
    CustomX almost 2 years

    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