Hey everyone,
I have the code below, but I have an issue with it. It copies correctly from My workbook into the desired Word Document, and to the desired bookmark, but it overwrites all of the contents of the Bookmarked Table. The table
has 4 lines of Headers and Info, but then I want all of it pasted below that in the Word Doc table format. below the 4 rows of Headers, there is 5 columns and the three columns I am copying from Excel should be pasted in Columns 2-4.
Any help is much appreciated!
Sub SendDatatoWord()
Dim MyRange As Excel.Range
Dim wd As Word.Application
Dim wdDoc As Word.Document
Dim wdRange As Word.Range
'Dim strdocname As String
Sheets("Inputs").Range("F3:H15").Copy
Set wd = New Word.Application
wd.Visible = True
'strdocname = ("C:\Users\1130569\Documents")
Set wdDoc = wd.Documents.Open("<path to file>\<document I want opened>.docm")
Set wdRange = wdDoc.Bookmarks("bk1").Range
On Error Resume Next
wdRange.Tables(1).delete
wdRange.Paste
'Adjust Column Widths
wdRange.Tables(1).Columns.SetWidth _
(MyRange.Width / MyRange.Columns.Count), wdAdjustSameWidth
wdDoc.Bookmarks.Add "bk1", wdRange
Set wd = Nothing
Set wdDoc = Nothing
Set wdRange = Nothing
End Sub
I have the code below, but I have an issue with it. It copies correctly from My workbook into the desired Word Document, and to the desired bookmark, but it overwrites all of the contents of the Bookmarked Table. The table
has 4 lines of Headers and Info, but then I want all of it pasted below that in the Word Doc table format. below the 4 rows of Headers, there is 5 columns and the three columns I am copying from Excel should be pasted in Columns 2-4.
Any help is much appreciated!
Sub SendDatatoWord()
Dim MyRange As Excel.Range
Dim wd As Word.Application
Dim wdDoc As Word.Document
Dim wdRange As Word.Range
'Dim strdocname As String
Sheets("Inputs").Range("F3:H15").Copy
Set wd = New Word.Application
wd.Visible = True
'strdocname = ("C:\Users\1130569\Documents")
Set wdDoc = wd.Documents.Open("<path to file>\<document I want opened>.docm")
Set wdRange = wdDoc.Bookmarks("bk1").Range
On Error Resume Next
wdRange.Tables(1).delete
wdRange.Paste
'Adjust Column Widths
wdRange.Tables(1).Columns.SetWidth _
(MyRange.Width / MyRange.Columns.Count), wdAdjustSameWidth
wdDoc.Bookmarks.Add "bk1", wdRange
Set wd = Nothing
Set wdDoc = Nothing
Set wdRange = Nothing
End Sub