Macro to copy table from excel to word

thisisrahul

Active Member
Joined
Sep 2, 2008
Messages
285
I am using the below code in MS Word to copy a table from excel file to word file.

..................................
Private Sub Document_Open()




Set wdapp = GetObject(, "Word.Application")
Dim tbl As Excel.Range
Dim wordoc As Word.Document


Dim xlApp As Object
Dim xlWB As Object
Dim BookmarkArray As Variant




BookmarkArray = Array("Rahul")


Set xlApp = CreateObject("Excel.Application")
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
Set xlWB = xlApp.Workbooks.Open("\\edenaswcmfps001\IE\ADD\Rahul Mishra\Add\Bulk Deals Database.xlsm", , , , "feelgood", "feelgood")
xlApp.Visible = True


With xlWB
'.Run "SelectHD1"
.Sheets("Aggregate").Selection.Copy
End With




Selection.GoTo What:=wdGoToBookmark, _
Name:="Rahul"


wdapp.Selection.Paste


'xlApp.CutCopyMode = False








End Sub
.......................................

The above code is working fine except the pasting of table as picture. I have selected the table in excel but stuck with copying the same and paste as picture on word file.
Also suggest me to save as the word file with "User_Name 30Nov2015.doc" where date is variable.


_________
Rahul
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You could either manually create the table in Word or VBA it, then open XL, gather the contents of the table in an array then populate the Word table. Else copy only the relevant range containing the table in XL (not the whole sheet). As far as file naming, it's just a matter of creating the string that U want...
Code:
Dim FLName as String, Month as String, Year as String
Month= "Nov"
Year = "2015"
FLName = "User_Name 30" & Month & Year & ".doc"
HTH. Dave
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,857
Members
449,051
Latest member
excelquestion515

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