Macro to copy table from excel to word

thisisrahul

Active Member
Joined
Sep 2, 2008
Messages
278
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
 

NdNoviceHlp

Well-known Member
Joined
Nov 9, 2002
Messages
2,402
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
 

Forum statistics

Threads
1,085,495
Messages
5,384,004
Members
401,871
Latest member
allemandi

Some videos you may like

This Week's Hot Topics

Top