Paste from Excel into word with correct formatting

Choch

New Member
Joined
Mar 6, 2018
Messages
7
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
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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