Hi,
I have the following VBA code which copies a range from Excel and pastes it into Word. Currently, the range is essentially pasted in the top left corner of the Word doc. It does this perfectly. However, I'd like to instead paste the table in a specific place. I've attached a sample Word doc and noted where the table should be inserted by writing "Paste Range here." For the record, that place seems to be the 31st line of the doc.
Thanks in advance, I really appreciate your help.
Sub CopyXLStoDOC()
'declare local variables and constants
Dim oDoc As Word.Document
Dim oWord As Word.Application
Dim rRange1 As Range, rRange2 As Range
Const sDocPath As String = "" 'if you wanted to open an existing Word doc, the address would go in between these quotes
'set ranges to copy
Set rRange1 = Worksheets("Sheet1").Range("A1:C10")
'open the Word document, if it doesn't exist, then create one
On Error Resume Next
Set oDoc = GetObject(sDocPath)
Set oWord = oDoc.Parent
If Err <> 0 Then
Set oWord = CreateObject("Word.Application")
Set oDoc = oWord.Documents.Add
End If
oWord.Visible = True
'copy and paste first range into Word
rRange1.Copy
oDoc.ActiveWindow.Selection.Paste
'Clean up objects
Set oDoc = Nothing
Set rRange1 = Nothing
Set rRange2 = Nothing
End Sub
Bookmarks