VBA code for copying excel ranges into an existing Word template

rjak

New Member
Joined
Feb 27, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi everyone

I am trying to copy from an existing excel template a specific range into an existing word doc. I get the error type 13 "Type mismatch". The error type 13 only pops up if I define more than one cell to copy.

Sub CreatWordReport()
Dim objWord
Dim objDoc
Dim objRange
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Summary")
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("C:\Users\xxx\Desktop\test1.docx")
objWord.Visible = True
Set objRange = objDoc.Bookmarks("ManagementSummary").Range
objRange.InsertAfter ws.Range("A2", Range("A2").End(xlDown).End(xlToRight)).Value
End Sub

Does anyone see the mistake or the reason why I get this kind of error?

Thanks a lot for answering
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try this instead

VBA Code:
Sub CreatWordReport()
    Dim objWord
    Dim objDoc
    Dim objRange
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("Summary")
    Set objWord = CreateObject("Word.Application")
    Set objDoc = objWord.Documents.Open("C:\TestArea\test1.docx")
    objWord.Visible = True
    Set objRange = objDoc.Bookmarks("ManagementSummary").Range
  
    ws.Range("A2", Range("A2").End(xlDown).End(xlToRight)).Copy
    objRange.PasteExcelTable False, False, False
End Sub

Above may not paste how you want - but there are several other (Word) paste methods
word paste.jpg
 
Upvote 0
Try this instead

VBA Code:
Sub CreatWordReport()
    Dim objWord
    Dim objDoc
    Dim objRange
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("Summary")
    Set objWord = CreateObject("Word.Application")
    Set objDoc = objWord.Documents.Open("C:\TestArea\test1.docx")
    objWord.Visible = True
    Set objRange = objDoc.Bookmarks("ManagementSummary").Range
 
    ws.Range("A2", Range("A2").End(xlDown).End(xlToRight)).Copy
    objRange.PasteExcelTable False, False, False
End Sub

Above may not paste how you want - but there are several other (Word) paste methods View attachment 7736
Hi Jongle

Thanks a lot for your clarification.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top