Reputation: 21
I'm trying to copy text and charts from Excel to Word. The problem is that the chart is always appearing on top of the Word document. How can I add the chart at the end of the Word document? Here is my code:
Sub Test()
Dim tbl As Excel.Range
Dim WordApp As Word.Application
Dim myDoc As Word.Document
Dim WordTable As Word.Table
Set WordApp = GetObject(class:="Word.Application")
WordApp.Visible = True
WordApp.Activate
'Create a New Document
Set myDoc = WordApp.Documents.Add
'Copy Excel Text in cell A1 to A3
Worksheets("Rapportage").Select
Range("A1:A3").Select
Selection.Copy
'Paste Excel Text into MS Word
myDoc.Paragraphs(1).Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False
'Copy Excel Chart
Worksheets("Rapportage").Select
Range("A4").Select
Selection.Copy
'Paste Chart into MS Word
myDoc.Paragraphs(1).Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False
End Sub
Upvotes: 2
Views: 834
Reputation: 7860
Replace
'Paste Excel Text into MS Word
myDoc.Paragraphs(1).Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False
with
'Paste Excel Text into MS Word
'add a paragraph at the end of the document and paste into it
with myDoc.Content
.InsertParagraphAfter
.Paragraphs.Last.Range.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False
End With
Upvotes: 1
Reputation: 446
This happens because in both paste commands you are pasting in Paragraphs(1). Instead, you could just paste using Selection, so it will paste one thing after another in the order that you want (it pastes where the cursor is):
'Paste Excel Text into MS Word
WordApp.Selection.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False
And, in the end:
'Paste Chart into MS Word
WordApp.Selection.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False
Upvotes: 0