!...........Excel VBA Program to Copy Activesheet data and paste into Ms-Word Table...........!
Sub copy_to_Word()
Dim doc As New Word.Application '' Tools->Reference->Microsoft Word 12.0 Object Library
Dim i, j As Integer
doc.Documents.Add
doc.ActiveDocument.Tables.Add Word.Selection.Range, ActiveSheet.Range("a1").End(xlDown).Row, ActiveSheet.Range("a1").End(xlToRight).Column
doc.ActiveDocument.Tables(1).Style = "table Grid"
doc.Visible = 1
For i = 1 To Range("a1").End(xlToRight).Column
For j = 1 To Range("a1").End(xlDown).Row
doc.ActiveDocument.Tables(1).Columns(i).Cells(j).Range = Cells(j, i).Value
Next j
Next i
doc.ActiveDocument.Save
ActiveWorkbook.Close savechanges = 1
End Sub
Sample file for the above VBA Program:----------------------------
Download Macro File
Download Macro File
No comments:
Post a Comment